Unity Tilemap Tutorial: Tile Palette, Rule Tiles and Colliders

Illustration of a 2D platformer level painted from glowing tiles

Building 2D levels by placing hundreds of individual sprite GameObjects gets slow fast. Unity’s Tilemap system lets you paint levels with a brush instead, and Rule Tiles pick the right edge and corner pieces automatically as you paint. This tutorial goes from a sprite sheet to a playable, collidable level in Unity 6: importing tiles correctly, painting with the Tile Palette, setting up Rule Tiles, adding efficient colliders, layering, and editing tiles from code. It ends with fixes for the famous thin lines between tiles.

Watch it in action: Rule Tiles, composite colliders and atlas padding in Unity 6.5 (4:14).


Packages You Need

If you started from a 2D project template, you already have what you need. Otherwise, install from Window > Package Manager:

  • 2D Tilemap Editor: the Tile Palette window and painting tools.
  • 2D Tilemap Extras: Rule Tiles, Animated Tiles and extra brushes. You want this one.

Importing Your Tile Sprites

Most tile problems start with import settings. Select your tileset image and set:

  • Texture Type: Sprite (2D and UI).
  • Sprite Mode: Multiple (for a sheet with many tiles).
  • Pixels Per Unit: your tile size in pixels. For 16ร—16 tiles, use 16. Then one tile is exactly one Unity unit and fills one grid cell.
  • Filter Mode: Point (no filter) for pixel art, otherwise tiles look blurry.
  • Compression: None for pixel art, to avoid color artifacts.

Click Apply, then open the Sprite Editor. Choose Slice > Grid By Cell Size, enter your tile size (16ร—16), and add any padding or offset your sheet uses. Click Slice, then Apply.

Creating a Tilemap and a Tile Palette

  1. In the Hierarchy, GameObject > 2D Object > Tilemap > Rectangular. This creates a Grid parent with a Tilemap child. Rename the child “Ground”.
  2. Open Window > 2D > Tile Palette. Click Create New Palette, name it, and save it in a folder like Assets/Tiles/Palettes.
  3. Drag your sliced tileset (or several selected sprites) from the Project window into the palette. Unity asks where to save the generated Tile assets. Pick a folder like Assets/Tiles/Ground.

Each tile in the palette is now a Tile asset pointing at one sprite. The palette is just a convenient layout for picking them.

Painting Tools

At the top of the Tile Palette window, make sure the Active Tilemap dropdown shows the tilemap you want to paint on. Then:

Tool Shortcut Use
Paint brush B Paint the selected tile(s)
Box fill U Fill a rectangle
Pick I Pick a tile from the scene (hold Ctrl while painting to pick quickly)
Eraser D Erase (or Shift + click with the brush)
Flood fill G Fill a connected area
Rotate / flip [ ] and Shift+[ ] Rotate or flip the tile before painting

You can select several tiles in the palette at once and paint them as a block, which is handy for multi-tile objects like trees or doors.

Layers and Sorting

Use several Tilemaps under the same Grid for different purposes. A typical platformer setup:

  • Background: decoration, no collision.
  • Ground: solid terrain, with colliders.
  • Foreground: grass and details drawn in front of the player.
  • Hazards: spikes, with a trigger collider.

Control draw order with the Tilemap Renderer‘s Sorting Layer and Order in Layer, the same as Sprite Renderers. Create Sorting Layers (Background, Ground, Player, Foreground) in Project Settings > Tags and Layers and assign them. That’s easier to manage than juggling order numbers.

For top-down games where the player should walk behind a tree trunk but in front of its base, sorting by layer isn’t enough. Set that tilemap’s Tilemap Renderer > Mode to Individual, so each tile is sorted on its own alongside your sprites, and sort by height: in URP, open your 2D Renderer Data asset and set Transparency Sort Mode to Custom Axis with the axis (0, 1, 0). Leave ground and wall tilemaps on the default Chunk mode, which batches tiles and is much cheaper; use Individual only where objects really need to slot in between tiles.

Adding Colliders

On the Ground tilemap, add a Tilemap Collider 2D. Every tile now gets its own collider shape. That works, but lots of small boxes cause two problems: slower physics, and characters catching on the seams between tiles as they run.

The fix is to merge them into one shape:

  1. Add a Composite Collider 2D to the same object. Unity also adds a Rigidbody 2D. Set its Body Type to Static, or your level will fall.
  2. On the Tilemap Collider 2D, set Composite Operation to Merge. (In Unity versions before 6, this is the Used By Composite checkbox.)

The green outline in the Scene view now traces the outside of the terrain as one shape. On the Composite Collider, Geometry Type: Outlines works well for ground. Use Polygons if you need to detect objects fully inside the shape.

Which tiles get colliders is set per Tile asset: select a tile and set Collider Type to Sprite (uses the sprite’s physics shape), Grid (full cell), or None (for decorative tiles on a solid tilemap).

For slopes or half-height tiles, a full-cell box is wrong. Open the tile’s sprite in the Sprite Editor, switch the dropdown at the top left to Custom Physics Shape, draw the outline you want, and click Apply. Tiles using that sprite with Collider Type Sprite now collide on the drawn shape, and the Composite Collider merges it with its neighbours like any other tile.

๐Ÿ’ป Building on a laptop?

2D projects are light, but Unity 6 still needs a decent machine for fast imports and smooth play mode. Our guide to budget laptops for Unity picks machines that handle it without overspending.

See the best budget laptops for Unity →

Unity Tilemap with 600 separate collider shapes next to a Composite Collider 2D merged into one shape.
TilemapCollider2D alone makes 600 shapes; Merge plus a Static body makes one.

Rule Tiles

Painting terrain by hand means choosing the top-left corner, top edge, inner corner and so on for every cell. A Rule Tile does it automatically: you paint with one tile, and it picks the correct sprite based on its neighbors.

  1. Create > 2D > Tiles > Rule Tile. Name it “Ground Rule”.
  2. Set a Default Sprite, usually the plain center fill.
  3. Add a rule for each piece. Each rule has a 3ร—3 grid around the center cell. Click cells to set them: a green arrow means “a tile of this Rule Tile must be here”, a red X means “must not be here”, and empty means “don’t care”.
  4. For a top edge: green arrows left, right and below; red X above. Assign the top-edge sprite. Repeat for the other edges and corners.
  5. Drag the Rule Tile into your palette and paint with it.

Rules are checked top to bottom and the first match wins, so put the most specific rules (inner corners) above general ones (edges). The Output option can also pick a random sprite from a list, which is great for breaking up repeated grass or stone.

Other useful tiles in 2D Tilemap Extras: Animated Tile (water, torches) and Random Brush for scattering decoration.

Unity Tilemap painted by hand with 20 of 80 wrong edge tiles next to the same terrain painted with a Rule Tile with 0 wrong.
Hand-painted tiles got 20 of 80 cells wrong; one Rule Tile got 0.

Fewer Rules, Variations and AutoTile

Let one rule cover four corners

Each tiling rule has a Rule type next to its sprite. Fixed matches only the exact pattern you drew. Rotated tries the pattern at 0, 90, 180 and 270 degrees, and Mirror X, Mirror Y and Mirror XY try flipped versions. If your outer corners are the same art turned round (common in top-down tilesets), one Rotated rule replaces four Fixed ones and the sprite is rotated for you. Platformer tilesets usually light their tops differently from their bottoms, so keep those rules Fixed.

Per-rule colliders and objects

Every rule has its own Collider (None, Sprite or Grid) and GameObject field. That means decorative edge pieces such as overhanging grass can skip collision while the solid fill keeps it, and a rule can spawn a prefab (a torch, a spawn marker) on the tiles it matches. Drag the prefab from the Project window, not the Hierarchy.

Random and animated output

Set a rule’s Output to Random and add several sprites to break up repetition. Noise controls how the choice is spread across the map; the pick is based on cell position, so repainting the same cell gives the same sprite. Shuffle also applies a random rotation or flip, which only suits art that has no lighting direction. Set Output to Animation for water or lava, with MinSpeed and MaxSpeed controlling playback speed.

Reskin with a Rule Override Tile

Once a Rule Tile works, don’t rebuild it for a snow or cave version. Create a Rule Override Tile from the same Create > 2D > Tiles menu, set its Tile field to your finished Rule Tile, and assign a replacement sprite for each original in the Override column. It reuses every rule, so a fix to the original rules carries over to all its skins.

AutoTile in newer Unity 6 versions

Recent versions of 2D Tilemap Extras add an Auto Tile (Create > 2D > Tiles > Auto Tile) that skips the rule list entirely. You set Mask Type to 2×2 (a 16-sprite set built from corners) or 3×3 (the full 47-sprite “blob” set), add your sliced texture under Used Textures, and click the parts of each sprite that are floor. Unity works out the matching itself and outlines duplicate masks in red. If your Package Manager shows it, it’s the quicker choice for standard tilesets; Rule Tiles are still more flexible for odd cases like one-way platforms or extended neighbour checks (the Extend Neighbor option lets a rule look beyond the 3×3 square).

Tilemaps from Code

You can read and change tiles at runtime, for example for destructible terrain, procedural levels, or checking what’s under the player:

using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.Tilemaps;

public class TileDigger : MonoBehaviour
{
    [SerializeField] Tilemap ground;
    [SerializeField] TileBase dirtTile;

    // Remove the tile under the mouse on click
    void Update()
    {
        Mouse mouse = Mouse.current;
        if (mouse == null || !mouse.leftButton.wasPressedThisFrame) return;

        Vector3 world = Camera.main.ScreenToWorldPoint(mouse.position.ReadValue());
        Vector3Int cell = ground.WorldToCell(world);

        if (ground.HasTile(cell))
            ground.SetTile(cell, null);
    }

    // Fill a rectangle, e.g. for a generated platform
    public void BuildPlatform(Vector3Int start, int width)
    {
        for (int x = 0; x < width; x++)
            ground.SetTile(start + new Vector3Int(x, 0, 0), dirtTile);
    }
}

For large changes, SetTiles with arrays of positions and tiles is much faster than calling SetTile in a loop. The Composite Collider updates automatically when tiles change.

The code above uses the Input System, which new Unity 6 projects use by default; the old Input.GetMouseButtonDown throws an InvalidOperationException when Active Input Handling is set to the Input System only. If you’re new to it, see our Input System troubleshooting guide.

A few more calls worth knowing:

  • GetCellCenterWorld(cell) gives the middle of a cell. CellToWorld returns its bottom-left corner, which is why pickups spawned with it sit off-centre.
  • BoxFill and SetTilesBlock fill whole rectangles in one call, which is ideal for procedural rooms.
  • RefreshAllTiles() makes every tile, including Rule Tiles, re-check its neighbours. Call it once after a big batch of changes if edges look wrong.
  • CompressBounds() shrinks the tilemap’s bounds to the tiles actually painted, so cellBounds doesn’t include old erased areas when you loop over it.
Unity Tilemap with a hole dug in the terrain using SetTile with null from code.
SetTile with null removes cells at runtime, so the player falls through.

Troubleshooting

Thin lines or gaps between tiles

The most common Tilemap complaint. Neighboring pixels bleed in at certain camera positions. Fixes, from most to least effective:

  • Pack the tiles into a Sprite Atlas (Create > 2D > Sprite Atlas) with padding of 2โ€“4 pixels. This fixes most cases.
  • Use Filter Mode Point and Compression None on the texture.
  • Add a Pixel Perfect Camera component (URP 2D) with your Pixels Per Unit, so the camera snaps to whole pixels.

Tiles are too big or too small for the grid

Pixels Per Unit doesn’t match your tile size. For 32ร—32 tiles, set it to 32 and click Apply.

Painting does nothing

Check the Active Tilemap dropdown in the Tile Palette window. You may be painting on a hidden or different tilemap. Also make sure the Scene view is in 2D mode and you’re looking at the right place.

The player gets stuck on flat ground

Each tile has its own collider and the player’s collider catches on the seams. Use a Composite Collider as described above, and give the player a capsule collider or rounded box.

The level falls when I press Play

The Rigidbody 2D added with the Composite Collider is Dynamic. Set it to Static.

Rule Tile picks the wrong sprite

Rules are checked in order. Move specific rules above general ones, and check that neighbors painted with a different tile count as “not this tile”.

Rule Tile edges appear where two terrains meet

“This” in a rule means this exact Rule Tile asset. A grass Rule Tile painted next to a dirt Rule Tile treats the dirt as empty space and draws an edge. Either paint the shared area with one Rule Tile and use a Rule Override Tile for the look, or accept the edge as a border between materials.

Rule Tile only ever shows the Default Sprite

No rule matched. Check that the green arrows and red Xs describe the neighbours that are actually there, and that you painted with the Rule Tile itself and not with the plain tiles generated from the same sheet. An empty tiling rules list can also throw errors in the inspector; add at least one rule.

There’s no Rule Tile option in the Create menu

The 2D Tilemap Extras package isn’t installed. It doesn’t come with the 2D Tilemap Editor package on its own.

Lines between tiles even with an atlas

Set the texture’s Mesh Type to Full Rect in its import settings (under Advanced). Tight mesh can leave tiny gaps at tile edges.

Unity Tilemap showing magenta lines between tiles when no sprite atlas padding is used.
Without atlas padding, bilinear filtering leaks gutter pixels as lines between tiles.

Still Broken? Check These

  1. Pixels Per Unit matches the tile size, and the Grid’s Cell Size is 1, 1, 0.
  2. Filter Mode is Point and Compression is None for pixel art.
  3. The Active Tilemap in the Tile Palette is the one you mean to paint on.
  4. The Composite Collider’s Rigidbody 2D is Static and the Tilemap Collider’s Composite Operation is Merge.
  5. Decorative tiles have Collider Type None, so they don’t block the player.
  6. Rules are ordered specific-first, and each rule’s Rule type (Fixed, Rotated, Mirror) is what you intended.
  7. Tilemaps use Sorting Layers in the right order, and top-down tilemaps that interleave with characters use Individual mode.
  8. Code uses the Input System or Active Input Handling allows the old Input Manager.

FAQ

How do I create a tilemap in Unity?

GameObject > 2D Object > Tilemap > Rectangular creates a Grid and a Tilemap. Then open Window > 2D > Tile Palette, create a palette and drag sprites in to paint.

Where is the Rule Tile in Unity?

It’s in the 2D Tilemap Extras package. After installing it, use Create > 2D > Tiles > Rule Tile.

How do I fix lines between tiles?

Pack tiles into a Sprite Atlas with padding, use Point filtering with no compression, and add a Pixel Perfect Camera for pixel art.

How do I add collision to a tilemap?

Add a Tilemap Collider 2D, then a Composite Collider 2D with a Static Rigidbody 2D, and set the Tilemap Collider’s Composite Operation to Merge.

Can I change tiles at runtime?

Yes. Use Tilemap.SetTile, GetTile, HasTile and WorldToCell. For many tiles at once, SetTiles is faster.

Does Tilemap support isometric and hexagonal maps?

Yes. Choose Isometric or Hexagonal when creating the tilemap, and there are matching Rule Tile types in Tilemap Extras.

Should I use a Rule Tile or an Auto Tile?

If your version of 2D Tilemap Extras has Auto Tile and your tileset is a standard 16 or 47 piece set, Auto Tile is faster to set up. Use a Rule Tile when you need custom logic, random or animated output per rule, or neighbour checks beyond the 3×3 square.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *