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.
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
- In the Hierarchy, GameObject > 2D Object > Tilemap > Rectangular. This creates a Grid parent with a Tilemap child. Rename the child “Ground”.
- Open Window > 2D > Tile Palette. Click Create New Palette, name it, and save it in a folder like
Assets/Tiles/Palettes. - 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.
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:
- 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.
- 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).
💻 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.
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.
- Create > 2D > Tiles > Rule Tile. Name it “Ground Rule”.
- Set a Default Sprite, usually the plain center fill.
- 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”.
- 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.
- 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.
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.Tilemaps;
public class TileDigger : MonoBehaviour
{
[SerializeField] Tilemap ground;
[SerializeField] TileBase dirtTile;
// Remove the tile under the mouse on click
void Update()
{
if (!Input.GetMouseButtonDown(0)) return; // or your Input System action
Vector3 world = Camera.main.ScreenToWorldPoint(Input.mousePosition);
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.
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”.
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.


Leave a Reply