Overview
Unity’s Tilemap system is the engine’s 2D level-painting workflow for tiled environments. Instead of placing hundreds of individual sprites manually, teams paint tiles onto a Grid using a Tile Palette. This is especially valuable for pixel-art games where environmental art is built from repeatable seamless tilesets. (Charles, 2D Game Graphics — Interactive Web Course, see source-2d-game-graphics-course)
Setup
Core Tilemap pieces:
| Tool | Role |
|---|---|
| Grid | The parent transform defining cell layout |
| Tilemap | A layer of painted tiles |
| Tile Palette | The editor palette used to paint tiles |
| Tileset sprites | The imported art that becomes paintable tiles |
Typical workflow:
- Import the tileset correctly using unity-pixel-art-pipeline.
- Create a Grid and Tilemap.
- Open the Tile Palette window.
- Drag sliced tile sprites into the palette to create tile assets.
- Paint the level directly in the Scene view.
Pixel art workflow note
For pixel art, the Tilemap workflow depends on three separate things lining up:
- the tileset import settings
- consistent Pixels Per Unit
- a correctly configured unity-pixel-perfect-camera
The Pixel Perfect Camera settings do not go on the Tilemap Renderer. The Tilemap Renderer just draws the tiles. Pixel-perfect presentation is a camera concern, while crisp tiles are also an import-settings concern.
Colliders and physics
A Tilemap has no collision until you add a collider. Unity’s tile collision is built from three pieces that sit on the Tilemap GameObject (the child of the Grid), plus a per-tile setting on each tile asset.
Step-by-step setup (Unity 6)
- Select the Tilemap GameObject that holds your solid tiles (ground, walls). Keep decorative tiles on a separate Tilemap without a collider.
- Add Component → Tilemap Collider 2D. Unity generates one collider shape per tile and draws them as green outlines in the Scene view (Unity Technologies, Unity Manual: Enable collision detection for tiles).
- Add Component → Composite Collider 2D. Unity merges the shapes of neighbouring tiles, which reduces the work the physics system has to do each update (Unity Technologies, Unity Manual: Enable collision detection for tiles). Composite Collider 2D requires a Rigidbody2D, so Unity adds one automatically (Unity Technologies, Scripting API: CompositeCollider2D).
- On the new Rigidbody2D, set Body Type to Static. The automatically added body is Dynamic, so if you skip this step gravity pulls the whole level down when you press Play. A static body never moves and is the right choice for level geometry (see unity-rigidbody2d).
- On the Tilemap Collider 2D, set Composite Operation to Merge. This tells the Composite Collider 2D to combine the tile shapes into one outline (Unity Technologies, Unity Manual: Tilemap Collider 2D component reference).
- On the Composite Collider 2D, choose the Geometry Type: Polygons gives solid shapes (like a Polygon Collider 2D) and Outlines gives hollow edges (like an Edge Collider 2D) (Unity Technologies, Unity Manual: Composite Collider 2D component reference). Polygons is the safer default for beginners, because a fast object that ends up inside a hollow outline is not pushed back out.
- Give the player its own Collider2D and a Dynamic Rigidbody2D (see unity-collider2d-and-triggers).
Unity 6 change: “Used By Composite” is gone. Older tutorials tell you to tick Used By Composite on the Tilemap Collider 2D. In Unity 6 that checkbox has been replaced by the Composite Operation dropdown (None, Merge, Intersect, Difference, Flip). In the Unity 6.3 engine assembly the old
Collider2D.usedByCompositeproperty is marked deprecated with the message “Please use compositeOperation”, so scripts should setcompositeOperation = Collider2D.CompositeOperation.Mergeinstead. When Composite Operation is anything other than None, the Composite Collider 2D controls the Material, Is Trigger and Used By Effector settings (Unity Technologies, Unity Manual: Tilemap Collider 2D component reference), so set friction and triggers on the composite, not on the Tilemap Collider 2D.
Per-tile Collider Type
Each tile asset (select it in the Project window) has a Collider Type that decides which shape the Tilemap Collider 2D generates for that tile (Unity Technologies, Unity Manual: Tile asset Inspector window reference):
| Collider Type | Shape used | Typical use |
|---|---|---|
| None | No collision | Background, grass tufts, decoration painted on the same Tilemap |
| Sprite | The sprite’s physics shape from the Sprite Editor’s Custom Physics Shape tab | Slopes, half-blocks, rounded or irregular tiles |
| Grid | The full tilemap cell | Square solid blocks; the cleanest and most predictable choice for platforms |
Colliders that follow the pixel art
For tiles that are not full squares, edit the physics shape once on the sprite and every painted copy of the tile uses it:
- Select the tileset texture and open the Sprite Editor.
- In the top-left dropdown choose Custom Physics Shape.
- Select a tile sprite and click Generate (or Generate All with no sprite selected) to create an outline that follows the opaque pixels. Outline Detail controls how closely it follows the art and Alpha Tolerance sets which pixels count as solid.
- Turn on Snap, which snaps the vertices to the nearest pixel, and adjust points by hand if needed.
- Click Apply, then make sure the tile’s Collider Type is Sprite.
(Unity Technologies, Unity Manual: Create collision shapes for a sprite and Custom Physics Shape tab reference for the Sprite Editor window.) If no custom shape is drawn, the sprite importer’s Generate Physics Shape option creates a default shape from the sprite’s outline (Unity Technologies, Unity Manual: Sprite texture type import settings). Because the shapes are in sprite pixels, they line up with the art as long as every sprite shares one Pixels Per Unit value (see unity-pixel-art-pipeline).
Pixel Perfect is a rendering setting, not a physics setting
Students often ask whether to apply “Pixel Perfect” before or after the Tilemap collider, or whether it goes on the Sprite Renderer, the Tilemap, or both to keep collision boundaries crisp. The answer is that the question mixes two separate systems:
- There is no Pixel Perfect setting on the Sprite Renderer or the Tilemap Renderer. The only component of that name for 2D scenes is the unity-pixel-perfect-camera, which goes on the camera. (The “Pixel Perfect” checkbox you may have seen belongs to a UI Canvas in Screen Space mode, which is a different system.)
- Pixel Perfect Camera changes only how the scene is drawn: the camera’s orthographic size, render resolution and on-screen snapping. Its Pixel Snapping option explicitly leaves sprites’ Transform positions unaffected (Unity Technologies, Unity Manual: Pixel Perfect Camera component reference for URP). It never touches Collider2D shapes, so the order in which you add the camera and the tile colliders makes no difference.
- Crisp collision boundaries come from the colliders themselves: Grid collider type for square tiles, a pixel-snapped Custom Physics Shape for irregular tiles, one project-wide PPU so pixels and world units agree, and a Composite Collider 2D so neighbouring tiles share one clean outline.
Changing tiles at runtime
The Tilemap Collider 2D updates its shapes in LateUpdate, batching several tile changes together. If a script removes a tile and needs the collider to be correct in the same frame, call ProcessTilemapChanges() (Unity Technologies, Unity Manual: Enable collision detection for tiles):
using UnityEngine;
using UnityEngine.Tilemaps;
public class BreakableTiles : MonoBehaviour
{
[SerializeField] Tilemap tilemap;
[SerializeField] TilemapCollider2D tilemapCollider;
public void BreakTileAt(Vector3 worldPosition)
{
Vector3Int cell = tilemap.WorldToCell(worldPosition);
tilemap.SetTile(cell, null); // remove the tile
if (tilemapCollider.hasTilemapChanges)
tilemapCollider.ProcessTilemapChanges(); // rebuild collision now
}
}Troubleshooting tile collision
| Symptom | Likely cause | Fix |
|---|---|---|
| The whole level falls when you press Play | The Rigidbody2D added by the Composite Collider 2D is Dynamic | Set its Body Type to Static |
| Player snags or stops at the joins between tiles | Each tile is a separate box, so the player’s collider catches on internal corners | Add a Composite Collider 2D and set Composite Operation to Merge; if small gaps remain, raise the Tilemap Collider 2D’s Extrusion Factor slightly so shapes overlap within the composite’s Vertex Distance |
| Player falls through the floor | Tile Collider Type is None; or the player has no Rigidbody2D/Collider2D; or a fast player passes through thin geometry | Check the tile asset’s Collider Type; check the player’s components; set the player’s Rigidbody2D Collision Detection to Continuous and prefer Polygons geometry |
| Collider outline does not match the art | Tile uses Grid instead of Sprite, or the custom shape was never applied | Set Collider Type to Sprite and draw or regenerate the Custom Physics Shape |
| Friction or Is Trigger changes have no effect | Composite Operation is not None, so the Composite Collider 2D owns those settings | Change them on the Composite Collider 2D |
| Decorations block the player | Decorative tiles share the collidable Tilemap | Move them to a separate Tilemap without a collider, or set their Collider Type to None |
The Extrusion Factor setting is documented for exactly this merging purpose (Unity Technologies, Unity Manual: Tilemap Collider 2D component reference). The snagging explanation and the Continuous collision advice are standard practice rather than claims from a single source; a capsule-shaped player collider, which slides over small corners more easily than a box, is a further common mitigation.
Usage
Tilemap is best when:
- the level is built from repeating 2D tiles
- alignment to a grid matters
- designers need to iterate on layout quickly
It complements rather than replaces art design pages like pixel-art-environment-art, which explain how to make a seamless tileset in the first place.
Gotchas
- If the import settings are wrong, the Tilemap will faithfully paint blurry art.
- Tilemap is ideal for regular grid-based spaces; highly irregular painted scenes may still be easier with layered sprites.
- Grid size and Pixels Per Unit must match the art style, or tiles will not line up cleanly.
- Tutorials written before Unity 2023 mention a Used By Composite checkbox. In Unity 6 use Composite Operation: Merge instead (see Colliders and physics).
- Adding a Composite Collider 2D silently adds a Dynamic Rigidbody2D; set it to Static.
Worked example
For a code-driven grid maze as a contrast to the Tilemap component, see the Pac-Man-lite teaching example (part of overview-arcade-classics-as-learning-projects):
- MazeGrid.cs — builds a grid maze in code with cell↔world conversion and BFS distance
Related
unity-pixel-art-pipeline · unity-pixel-perfect-camera · unity-aseprite-importer · unity-collider2d-and-triggers · unity-rigidbody2d · collider2d · pixel-art-environment-art · cellular-automata · source-2d-game-graphics-course · unity-2d-lighting