【Unity】Unity 2D Tilemap Basics: Tile Palette, Collision, Layers & Rule Tiles

Created: 2026-07-12

Build 2D game terrain efficiently with Tilemaps. Learn how Grid, Tilemap, and Tile Palette relate, how to add collision with Tilemap Collider 2D and Composite Collider 2D, how to split ground and decoration into layers, how to automate borders with Rule Tiles, and how to place tiles from scripts with SetTile.

Ground, walls, caves, cityscapes — placing them one Sprite at a time for a 2D game is mind-numbing work. That's what the Tilemap is for: a system that lays small tiles (images) out on a grid to assemble large maps efficiently. Got your sprites and sprite sheets ready, but stuck on how to actually build the stage?

This article walks through the foundation of 2D stage building: the three parts of a Tilemap (Grid, Tilemap, Tile Palette), how to add collision to tiles, how to split ground and decoration into layers, how Rule Tiles auto-place border tiles, and how to place tiles from a script.

The idea of a Tilemap: pick small tiles from a palette and paint them onto a grid to assemble a 2D stage with ground and walls

What you'll learn

  • How Grid, Tilemap, and Tile Palette relate (grid, map, paint box)
  • Adding collision to tiles (Tilemap Collider 2D + Composite)
  • Splitting ground and decoration into multiple Tilemaps (Sorting Layer)
  • Auto-placing border tiles with Rule Tile (2D Tilemap Extras)
  • Practice: placing tiles from a script with SetTile

Tested on: Unity 2022.3 LTS / Unity 6

Sponsored

Grid, Tilemap, and Tile Palette

A Unity tilemap is made of three parts. Nail down how they relate and the rest of this article reads smoothly.

Diagram of the three Tilemap parts: a Grid (parent grid) has a Tilemap (the map you lay tiles onto) as a child, and you paint tiles from a Tile Palette (a paint box of registered tiles) onto the Tilemap
PartRole
GridThe parent GameObject that manages the grid tiles are placed on. Sets the cell size
TilemapThe child component that actually lays tiles on that grid. One "map"
Tile PaletteThe paint box holding usable tiles. You pick tiles here and paint

Steps to build one

  1. Right-click in the Hierarchy → choose 2D Object > Tilemap > Rectangular, and a Grid + Tilemap are created automatically
  2. Open Window > 2D > Tile Palette, then Create New Palette to make a new palette
  3. Drag a sliced sprite sheet (the one you made in sprites and sprite sheets) onto the palette. Each cell registers as a "usable tile"
  4. Pick a tile in the palette and brush across the Scene view to paint

That's all it takes to lay down wide floors and walls in an instant. No need to place Sprites one cell at a time.

Note: One Tile Palette (paint box) can be shared across multiple Tilemaps (maps). One paint box, any number of maps — that's the basic pattern.

Adding collision to tiles

The player walks on the floor and stops at walls — this collision gets applied across all the tiles you've laid, just by adding components to the Tilemap.

Diagram of Tilemap collision: Tilemap Collider 2D creates a collider on each individual tile, but adding a Composite Collider 2D merges adjacent tile colliders into a single outline, removing snags and running lighter
  1. Add a Tilemap Collider 2D to the terrain Tilemap. This automatically creates collision everywhere tiles are laid
  2. Also add a Composite Collider 2D (a Rigidbody 2D comes along with it, so set its Body Type to Static)
  3. Check Used By Composite on the Tilemap Collider 2D

There are two reasons to add the Composite Collider 2D. The per-tile colliders merge into a single outline, which eliminates the bug where the player snags on tile seams. And the collider count drops dramatically, so it runs lighter, keeping wide maps snappy. The player (Rigidbody 2D + Collider 2D) can now walk on this terrain (see Rigidbody2D and Collider2D).

Sponsored

Layering with multiple Tilemaps

You can build a map with a single Tilemap, but splitting Tilemaps by role makes management far easier. Hang multiple GameObjects with Tilemaps under the Grid.

Diagram of layering with multiple Tilemaps: under one Grid, three Tilemaps (background, ground, decoration) stack and combine into one finished map. Collision is only on the ground Tilemap
Grid
├── Background (Tilemap)   # Background (sky, distant view). No collision
├── Ground (Tilemap)       # Ground, walls. Tilemap Collider 2D + Composite
└── Decoration (Tilemap)   # Grass, props. Layered over ground. No collision
  • Draw order (front/back): decided by each Tilemap's Tilemap Renderer Sorting Layer and Order in Layer. Higher numbers draw in front. To layer grass over the ground, set Decoration's Order higher than Ground.
  • Separation of roles: give collision only to Ground, and keep Background and Decoration (grass, signs) collision-free. The trick is not to mix "solid ground" with "decoration only."

Sorting Layer is shared across all Sprites. The player's SpriteRenderer Sorting Layer/Order is compared on the same field, so adjustments like "bring the player in front of decoration" happen here too. See layers and tags for more.

Automating borders with Rule Tile

The seam between grass and dirt, wall corners, road bends — picking these border tiles one by one is tedious. That's what Rule Tile is for: the engine looks at surrounding tiles and automatically picks the right one.

Diagram of Rule Tile: painting the middle makes the engine look at the surroundings and auto-select corner, edge, and center tiles. Instead of placing corners and edges by hand, the borders finish cleanly just by painting

Rule Tile isn't a built-in feature; it ships in the 2D Tilemap Extras package.

  1. Install com.unity.2d.tilemap.extras (2D Tilemap Extras) in the Package Manager
  2. Create a Rule Tile asset via Create > 2D > Tiles > Rule Tile
  3. Set up rules like "use the center tile if the same tile is above/below/left/right, otherwise use the edge tile," and assign a sprite to each pattern
  4. Register this Rule Tile in the palette and paint

Once the rules are set, the borders connect automatically just by painting terrain. No more hunting for corner tiles by hand — map building gets a lot faster.

Start with plain tiles: Rule Tile is powerful but takes effort to set up. Build your map with plain tiles first, and introduce it once you feel "placing borders by hand every time is painful."

Practice: placing tiles from a script

Tiles aren't just hand-painted in the editor — you can place them dynamically from code. Roguelike dungeon generation, sandbox terrain destruction, simulation terrain generation — it shines in "build the map by rules" genres.

Diagram of tile placement with SetTile: calling tilemap.SetTile(cell coordinate, tile) places that tile at the given grid coordinate. Loop over coordinates with a nested loop and repeat SetTile to lay a floor programmatically

The key is SetTile(). You specify "place this tile at this cell coordinate." The coordinate is a Vector3Int (grid cell coordinate), which is different from world coordinates (pixels).

using UnityEngine;
using UnityEngine.Tilemaps;

public class DungeonGenerator : MonoBehaviour
{
    [SerializeField] private Tilemap groundTilemap;
    [SerializeField] private TileBase floorTile;  // Assign the tile asset in the Inspector

    void Start()
    {
        // Lay a 20x15 floor all at once
        for (int x = 0; x < 20; x++)
        {
            for (int y = 0; y < 15; y++)
            {
                // Place the floor tile at cell coordinate (x, y)
                groundTilemap.SetTile(new Vector3Int(x, y, 0), floorTile);
            }
        }

        // Erase the tile at cell coordinate (5, 5) (poke a hole)
        groundTilemap.SetTile(new Vector3Int(5, 5, 0), null);
    }
}

Two points to remember. "Don't confuse cell coordinates with world coordinates" (SetTile takes a cell coordinate; to get a cell from a world coordinate like the mouse position, convert with tilemap.WorldToCell(worldPos), and the reverse is CellToWorld), and "pass null to erase" (SetTile(position, null) empties that cell; for bulk replacement, SetTilesBlock processes many at once and is faster). The generation algorithm itself just decides "which cells become floor" — pick coordinates with a random walk or cellular automata, then just lay them with SetTile.

Good to know first

  • Tiles look blurry or have seams: set your tile sprites' Filter Mode to Point (no filter) and Compression to None for crisp results. If thin lines appear between tiles, set the sprite's Mesh Type to Full Rect or use a padded sprite sheet.
  • Want enemies to walk on the map: Tilemap-based AI pathfinding is weakly supported by Unity's built-in 2D NavMesh, so A*-style assets or a homemade grid search are common. For 3D pathfinding, see AI pathfinding with NavMesh.
  • Scroll wide maps with the camera: for maps bigger than the screen, follow the player with Cinemachine. A Confiner to hide the edges is a classic setup.
  • You can make Isometric (quarter-view) too: choose 2D Object > Tilemap > Isometric for a diagonal top-down tilemap. The basics are the same — only the Grid's Cell Layout changes.

Summary

  • Build maps from three parts: Grid (the grid), Tilemap (the map), and Tile Palette (the paint box). The palette can be shared across multiple Tilemaps
  • Collision is Tilemap Collider 2D + Composite Collider 2D (Rigidbody 2D as Static). Seam snags disappear and it runs lighter
  • Split ground and decoration into Tilemaps by role, and control front/back with Sorting Layer / Order in Layer
  • Auto-place border tiles with Rule Tile (2D Tilemap Extras). Corners and edges connect just by painting
  • Place tiles from a script with SetTile(cell coordinate, tile). Pass null to erase

Start by laying floor tiles, add a Tilemap Collider 2D + Composite Collider 2D, and get to the point where the player can walk on top. The Tilemap is the foundation of 2D stage building. What kind of terrain will your 2D world begin with?

Further reading