Unity 2D Tilemap
Author and script tile-based 2D levels in Unity 6.3 LTS with the Grid/Tilemap system, the Tile
Palette, colliders, and runtime painting. Targets Unity 6.3 LTS (6000.3).
Package note: the core Tilemap (Grid, Tilemap, Tile, TilemapCollider2D) is
built in. Rule Tiles, Animated Tiles, and Tile Palette brushes live in the separate
"2D Tilemap Extras" package (com.unity.2d.tilemap.extras) — install it via Package
Manager before using RuleTile.
When to use
- Use when laying out a 2D level by painting tiles, setting up a
Grid + Tilemap, adding
collision to the map, using auto-tiling Rule Tiles, or generating/editing tiles from script.
- Use when scenes contain a
Grid with Tilemap children, or *.asset tile/palette files.
When not to use: level design practice (pacing, blockout, layout principles) →
level-design. 3D tile/grid placement → Unity's own 3D tooling (ProBuilder / grid brushes; no dedicated skill here). The platformer character that
moves over the tiles → platformer / unity-physics.
Core workflow
- Create the grid: GameObject → 2D Object → Tilemap → Rectangular. This makes a
Grid
with a child Tilemap (+ TilemapRenderer). Use one Tilemap per layer (background,
ground, foreground) and set each renderer's sorting.
- Open the Tile Palette (Window → 2D → Tile Palette), drag in a sliced sprite sheet to
create
Tile assets, then paint with the brush tools.
- Add collision to the solid layer:
TilemapCollider2D. For one merged collider (far
cheaper and gap-free), also add CompositeCollider2D (+ a Rigidbody2D set to Static)
and enable Used By Composite on the tilemap collider.
- Auto-tile with Rule Tiles (2D Tilemap Extras) so edges/corners pick the right sprite
automatically instead of hand-placing every variant.
- Edit at runtime via script with cell coordinates (
Vector3Int): SetTile, GetTile,
SetTilesBlock, converting world↔cell with the Grid/Tilemap.
- Verify in Play mode: confirm collisions (Physics Debugger), sorting order, and that
RefreshAllTiles ran after bulk edits.
Patterns
1. Painting tiles at runtime (cell coordinates)
using UnityEngine;
using UnityEngine.Tilemaps;
public class TilePainter : MonoBehaviour
{
[SerializeField] private Tilemap tilemap; // assign the target Tilemap
[SerializeField] private TileBase groundTile;
// World position -> cell, then place a tile.
public void PaintAt(Vector3 worldPos)
{
Vector3Int cell = tilemap.WorldToCell(worldPos);
tilemap.SetTile(cell, groundTile);
}
public bool IsSolid(Vector3 worldPos)
=> tilemap.GetTile(tilemap.WorldToCell(worldPos)) != null;
}
2. Bulk fill a region (faster than per-cell SetTile)
// SetTilesBlock writes a whole BoundsInt in one call — use it for procedural rooms/floors.
public void FillFloor(Tilemap map, TileBase tile, int width, int height)
{
var bounds = new BoundsInt(0, 0, 0, width, height, 1);
var tiles = new TileBase[width * height];
for (int i = 0; i < tiles.Length; i++) tiles[i] = tile;
map.SetTilesBlock(bounds, tiles);
}
3. Clearing and refreshing
tilemap.SetTile(cell, null); // null erases the tile at that cell
tilemap.RefreshTile(cell); // re-evaluate just this cell's rule/animated neighbors (cheap)
// RefreshAllTiles() re-evaluates the ENTIRE map — reserve it for full regenerations, not per-edit.
Pitfalls
RuleTile type not found — it's not built in. Install the 2D Tilemap Extras package
(com.unity.2d.tilemap.extras) via Package Manager.
- A collider per tile tanks performance / leaves seams — add a
CompositeCollider2D with a
static Rigidbody2D and Used By Composite to merge the whole layer into one smooth shape.
- Confusing world and cell coordinates —
SetTile/GetTile take a Vector3Int cell,
not a world position. Always convert with WorldToCell / CellToWorld.
- Tiles render behind/in front of sprites unexpectedly — set each
TilemapRenderer's
Sorting Layer and Order in Layer; multiple tilemaps need explicit ordering.
- Rule/animated tiles don't update after script edits — refresh after writes, but prefer
the targeted
RefreshTile(cell) for a few edits; RefreshAllTiles() re-evaluates every tile
on the map and stalls large levels. Reserve the full refresh for whole-map regenerations.
- Painting onto the wrong layer — the active target Tilemap in the Tile Palette determines
where paint lands; check the "Active Tilemap" dropdown.
References
- Primary docs: Unity Manual "Tilemaps"
(
https://docs.unity3d.com/Manual/tilemaps/work-with-tilemaps/tilemap-reference.html),
ScriptReference/Tilemaps.Tilemap, and the 2D Tilemap Extras package manual
(https://docs.unity3d.com/Packages/com.unity.2d.tilemap.extras@1.6/manual/index.html) for
Rule Tiles.
Related skills
level-design — engine-agnostic blockout, pacing, and tile layout practice.
procedural-gen — generating the tile data (noise, RNG, dungeons) you feed to SetTilesBlock.
platformer / roguelike — genres that compose this skill with movement and generation.
1---
2name: unity-tilemap-2d
3description: >
4 Build and script 2D tilemaps in Unity 6.3 LTS: the Grid + Tilemap components, the Tile Palette,
5 tilemap colliders, rule tiles, and runtime SetTile/GetTile painting. Use when painting tile
6 levels, adding a TilemapCollider2D, using rule or animated tiles, generating tilemaps from
7 code, or when the user mentions Unity tilemap, tile palette, rule tile, or Grid.
8---
9
10# Unity 2D Tilemap
11
12Author and script tile-based 2D levels in Unity 6.3 LTS with the `Grid`/`Tilemap` system, the Tile
13Palette, colliders, and runtime painting. Targets **Unity 6.3 LTS (6000.3)**.
14
15> **Package note:** the core Tilemap (`Grid`, `Tilemap`, `Tile`, `TilemapCollider2D`) is
16> built in. **Rule Tiles, Animated Tiles, and Tile Palette brushes live in the separate
17> "2D Tilemap Extras" package (`com.unity.2d.tilemap.extras`)** — install it via Package
18> Manager before using `RuleTile`.
19
20## When to use
21
22- Use when laying out a 2D level by painting tiles, setting up a `Grid` + `Tilemap`, adding
23 collision to the map, using auto-tiling Rule Tiles, or generating/editing tiles from script.
24- Use when scenes contain a `Grid` with `Tilemap` children, or `*.asset` tile/palette files.
25
26**When _not_ to use:** level _design_ practice (pacing, blockout, layout principles) →
27`level-design`. 3D tile/grid placement → Unity's own 3D tooling (ProBuilder / grid brushes; no dedicated skill here). The platformer character that
28moves over the tiles → `platformer` / `unity-physics`.
29
30## Core workflow
31
321. **Create the grid:** GameObject → 2D Object → Tilemap → Rectangular. This makes a `Grid`
33 with a child `Tilemap` (+ `TilemapRenderer`). Use one Tilemap per layer (background,
34 ground, foreground) and set each renderer's sorting.
352. **Open the Tile Palette** (Window → 2D → Tile Palette), drag in a sliced sprite sheet to
36 create `Tile` assets, then paint with the brush tools.
373. **Add collision** to the solid layer: `TilemapCollider2D`. For one merged collider (far
38 cheaper and gap-free), also add `CompositeCollider2D` (+ a `Rigidbody2D` set to **Static**)
39 and enable _Used By Composite_ on the tilemap collider.
404. **Auto-tile with Rule Tiles** (2D Tilemap Extras) so edges/corners pick the right sprite
41 automatically instead of hand-placing every variant.
425. **Edit at runtime via script** with cell coordinates (`Vector3Int`): `SetTile`, `GetTile`,
43 `SetTilesBlock`, converting world↔cell with the `Grid`/`Tilemap`.
446. **Verify** in Play mode: confirm collisions (Physics Debugger), sorting order, and that
45 `RefreshAllTiles` ran after bulk edits.
46
47## Patterns
48
49### 1. Painting tiles at runtime (cell coordinates)
50
51```csharp
52using UnityEngine;
53using UnityEngine.Tilemaps;
54
55public class TilePainter : MonoBehaviour
56{
57 [SerializeField] private Tilemap tilemap; // assign the target Tilemap
58 [SerializeField] private TileBase groundTile;
59
60 // World position -> cell, then place a tile.
61 public void PaintAt(Vector3 worldPos)
62 {
63 Vector3Int cell = tilemap.WorldToCell(worldPos);
64 tilemap.SetTile(cell, groundTile);
65 }
66
67 public bool IsSolid(Vector3 worldPos)
68 => tilemap.GetTile(tilemap.WorldToCell(worldPos)) != null;
69}
70```
71
72### 2. Bulk fill a region (faster than per-cell `SetTile`)
73
74```csharp
75// SetTilesBlock writes a whole BoundsInt in one call — use it for procedural rooms/floors.
76public void FillFloor(Tilemap map, TileBase tile, int width, int height)
77{
78 var bounds = new BoundsInt(0, 0, 0, width, height, 1);
79 var tiles = new TileBase[width * height];
80 for (int i = 0; i < tiles.Length; i++) tiles[i] = tile;
81 map.SetTilesBlock(bounds, tiles);
82}
83```
84
85### 3. Clearing and refreshing
86
87```csharp
88tilemap.SetTile(cell, null); // null erases the tile at that cell
89tilemap.RefreshTile(cell); // re-evaluate just this cell's rule/animated neighbors (cheap)
90// RefreshAllTiles() re-evaluates the ENTIRE map — reserve it for full regenerations, not per-edit.
91```
92
93## Pitfalls
94
95- **`RuleTile` type not found** — it's not built in. Install the **2D Tilemap Extras** package
96 (`com.unity.2d.tilemap.extras`) via Package Manager.
97- **A collider per tile tanks performance / leaves seams** — add a `CompositeCollider2D` with a
98 static `Rigidbody2D` and _Used By Composite_ to merge the whole layer into one smooth shape.
99- **Confusing world and cell coordinates** — `SetTile`/`GetTile` take a `Vector3Int` _cell_,
100 not a world position. Always convert with `WorldToCell` / `CellToWorld`.
101- **Tiles render behind/in front of sprites unexpectedly** — set each `TilemapRenderer`'s
102 Sorting Layer and Order in Layer; multiple tilemaps need explicit ordering.
103- **Rule/animated tiles don't update after script edits** — refresh after writes, but prefer
104 the targeted `RefreshTile(cell)` for a few edits; `RefreshAllTiles()` re-evaluates every tile
105 on the map and stalls large levels. Reserve the full refresh for whole-map regenerations.
106- **Painting onto the wrong layer** — the active target Tilemap in the Tile Palette determines
107 where paint lands; check the "Active Tilemap" dropdown.
108
109## References
110
111- Primary docs: Unity Manual "Tilemaps"
112 (`https://docs.unity3d.com/Manual/tilemaps/work-with-tilemaps/tilemap-reference.html`),
113 `ScriptReference/Tilemaps.Tilemap`, and the 2D Tilemap Extras package manual
114 (`https://docs.unity3d.com/Packages/com.unity.2d.tilemap.extras@1.6/manual/index.html`) for
115 Rule Tiles.
116
117## Related skills
118
119- `level-design` — engine-agnostic blockout, pacing, and tile layout practice.
120- `procedural-gen` — generating the tile data (noise, RNG, dungeons) you feed to `SetTilesBlock`.
121- `platformer` / `roguelike` — genres that compose this skill with movement and generation.