Skip to main content

Tilemaps

A tilemap is a whole level made of square tiles painted on a grid: ground, walls, platforms, water, flowers. It is one object and one mesh, however many tiles it has, so big levels stay fast. Tiles you mark solid block the player and other physics bodies, and you can change tiles while the game runs (open a door, break a block).

It is made for a 2D side view (see 2D games), but a tilemap is just a flat grid standing in the 3D world: you can lay it flat as a floor too.

The tile sheet​

The tiles come from a tile sheet: a picture made in the sprite editor where every frame is one tile. Make a sprite the size of one tile (for example 64 × 64), draw one tile per frame, and save. Tile 0 is the first frame, tile 1 the second, and so on.

The Tilemap card with its tile sheet and palette
The Tilemap card with its tile sheet and palette

Cut a sheet from an image​

Tile art usually comes as one picture full of equal squares. Instead of redrawing it, cut it: Files → + New → Sprite sheet from an image… (or, in the Tilemap card, ✂️ New tile sheet → Cut it from an image…).

  1. Pick the picture.
  2. Type the size of one piece in pixels, such as 64 or 64 x 32.
  3. Give the sheet a name.
  4. Tap the pieces to keep (or drag over several). Empty pieces start turned off. All and None help. Tap Make sheet.
Tap the pieces you want: the blue ones are kept
Tap the pieces you want: the blue ones are kept

The kept pieces go side by side in a new sprite sheet, in reading order (left to right, top to bottom). A sheet can be 4096 pixels wide, so at 64 px that is up to 64 pieces; when the picture has more, it starts with none selected so you can choose. The same works for a character picture: each piece becomes a frame of a sprite.

A tile's number is the position of its frame in the sheet. You can still edit the sheet freely: when you Save the sprite editor after inserting, duplicating or moving frames, the editor renumbers your tilemaps for you. Painted cells, solid / one-way / climbable settings and auto tile sets all follow their pictures. New frames count as solid. If you delete a frame that painted cells use, the editor asks first, and then erases those cells (and drops any auto tile set that used the frame).

You can also use the sheet of the 2D Platformer template (grass and earth pieces, floating platforms, a bush and a mushroom).

Add a tilemap​

Objects → + Add, under Sprites: Tilemap. It starts with the first sprite sheet of your project (change it with Tile sheet; 🖌️ New tile sheet draws one, ✏ Edit reopens the sheet you picked). A Collider is added too, so solid tiles block.

Paint​

Tap 2D in the 3D view's toolbar first: it gives a flat front view with a vertical grid, so each cell is easy to hit (see the 2D view). Then select the tilemap and tap 🖌️ Paint tiles. Now a drag in the 3D view paints; a faint grid and a yellow square show the cell under your finger. While painting, one finger paints; use two fingers (or the right mouse button) to move and zoom the view. Tap ✋ Stop painting when you are done, or select something else.

Painting on: tools and palette
Painting on: tools and palette
ToolWhat it does
🖌️ DrawPaints the chosen tile on every cell you drag over.
🧽 EraseEmpties the cells you drag over.
🪣 FillFills the area you tap: connected cells of the same tile (or, on empty ground, the empty space inside what you have painted, plus a margin). Limited to 5000 cells.

The palette shows every tile of the sheet; tap one to choose it (the chosen tile has a blue frame). One drag is one Undo step.

What a tile does​

Every tile of the sheet has a behavior: does it block, can you stand on it, can you climb it, or is it only a picture? You set this per tile number, not per painted cell.

That is the one idea to remember:

Tile 6 is one-way means every cell in this tilemap that shows Tile 6 is one-way: the ones you already painted, and the ones you paint later.

Think of the palette as a list of building blocks. You decide once what each block does, and then every place you used that block follows. You don't have to go back and fix cells.

Set it​

  1. Tap a tile in the palette (it gets a blue frame). The tile's number is in the button right under the palette.
  2. Tap the button under the palette, All tile 6: 🧱 Solid ⟳. Each tap goes to the next kind: Solid → One-way → Walkthrough → Solid.
  3. Tap 🪜 Climbable beside it to turn climbing on or off for that tile. It is separate from the three kinds above.

The button always talks about the tile you chose in the palette: choose another tile and the button changes to show that tile's behavior.

KindWhat it doesUse it for
🧱 SolidBlocks from every side. This is the default for every tile.Ground, walls, blocks.
⬆ One-wayBlocks only from above. A character can jump up through it from below and land on it, walks through it sideways, and can drop down through it (see below).Floating platforms, ledges, the top of a ladder.
◻ WalkthroughDoes nothing: the tile is only a picture.Bushes, flowers, background, signs.
🪜 ClimbableA character with Climb on can grab it and climb up and down. Usually a Walkthrough tile.Ladders, vines, ropes.

See what each tile does​

While a tilemap is selected, the 3D view draws a small mark on every cell, so you can see what each placed tile does without guessing. The marks only show in the editor, never in the game.

Yellow lines on top: one-way. Cyan ladder: climbable. Small ring: walkthrough. Solid tiles have no mark.
Yellow lines on top: one-way. Cyan ladder: climbable. Small ring: walkthrough. Solid tiles have no mark.
MarkMeans
Yellow lines along the top of the tileOne-way platform
Cyan ladder drawn on the tileClimbable
Small white ring in the middleWalkthrough
NothingSolid

Change a tile's kind and its marks change at once on every cell that uses it. This is the fastest way to check that you set the right tile.

Two spots, two behaviors​

Because behavior belongs to the tile number, one tile number can't be solid in one place and one-way in another inside the same tilemap. Two easy ways to get both:

  • Put the picture in the sheet twice. In the sprite editor (✏ Edit on the Tilemap card), duplicate the frame (⧉) and save. Now the sheet has two tiles that look the same. Make one Solid and the other One-way. The 2D Platformer template does this idea: the ground tiles are solid, and the platform tiles (their own tile numbers) are one-way.
  • Use two tilemaps (see Layers below). Add a second Tilemap object (for example Ground and Platforms). The settings belong to each Tilemap object, so the same tile sheet can be solid in one and one-way in the other. Giving them different Sort order values keeps the drawing order you want.

Solid and one-way tiles in the game​

Solid and one-way tiles that touch are merged into as few collision boxes as possible, so a long floor is one collider: the player never catches on the seam between two tiles. The boxes are as deep as Collider depth says (front to back, in meters).

note

Tiles block only when the object has a Collider component (set to Auto). Without it the tilemap is only a picture, and Walkthrough looks the same as Solid.

How a one-way tile behaves:

  • Standing on it works like any floor.
  • From below, a character that is moving up passes straight through. Once it is on top and falling, it lands.
  • Sideways, a character walks through the edge of the tile if its feet are below the top.
  • Drop down: with a Platformer in Side view, press Down and jump to fall through the platform you stand on.
  • A one-way tile does not move or turn. For a moving platform use a separate object.

Questions​

I changed a tile and cells I painted before changed too. Is that a bug? No. The kind belongs to the tile, so every cell with that tile follows. Look at the marks to see which cells use the tile.

I want only some ground tiles to be one-way. Use a different tile number for them: duplicate the frame in the sheet, or use a second Tilemap. See Two spots, two behaviors above.

Another tilemap uses the same sheet. Does it change too? No. The kinds are saved on each Tilemap object, so each tilemap has its own settings for the same sheet.

Do auto tiles follow this? Yes. An auto tile set only paints tile numbers, so each of its pieces behaves as its tile number is set.

Coming from Unity or Godot? In Unity a tile asset has its own collider type, and a one-way platform is usually done for a whole tilemap with a Platform Effector, so people keep a separate "Platforms" tilemap. In Godot the tile set holds each tile's collision, including a one-way checkbox, and every tilemap that uses the set shares it. Here the setting is per tile number like those, but saved on each Tilemap object.

Auto tiles​

Painting every edge and corner of a hill by hand is slow. With auto tiles you paint the ground and the engine picks the right piece for each cell: a corner at the corners, a flat top along the top, a middle inside. Erase a cell and the pieces around it round themselves off.

Auto tile sets under the palette
Auto tile sets under the palette

Set one up in the Tilemap card, under Auto tiles:

  • + Block (9 pieces) for ground, walls and hills. You tap the tile for each piece in turn: top left, top, top right, left, middle, right, bottom left, bottom, bottom right. The pieces are laid out as they will meet.
  • + Platform (3 pieces) for a one-tile-high floating platform: left end, middle, right end.
Tap the tile for each piece; tap a piece above to change it
Tap the tile for each piece; tap a piece above to change it

Tap a piece in the grid to go back to it, and Done when all are filled. Each set's row shows all its pieces, and in the palette every tile that is a piece of an auto tile set has a small A mark (a tile that is also an animation frame shows ▶A). Give the set a name. Then tap its name in the list to paint with it (the same drag as Draw). To change or redo a set, delete it (🗑) and make it again.

One drag with the Earth set: corners and edges fit by themselves
One drag with the Earth set: corners and edges fit by themselves

How it works: a cell belongs to a set when its tile is one of the set's pieces. Each cell looks at its four neighbours (up, right, down, left) that belong to the same set and picks its piece from that. So you can also Draw a piece by hand, Erase or Fill, and the neighbouring pieces update. A tile that is not a piece of any set is never changed. In events and scripts, Erase tile / removeTile and setTile also update the pieces next to the changed cell, so digging a hole in the ground leaves rounded edges.

Rule tiles​

A rule tile (Unity's Rule Tile) is an auto tile you write the rules for: any number of pieces, inner corners, slopes, or a random pick from a few tiles so a long floor doesn't repeat.

A hilly ground painted with one rule tile: every edge and corner piece was picked by its rules

Tap + Rule tile, pick its Default tile (the one a cell shows when no rule matches) and name it. Then + Rule adds a rule. Each rule is a 3 × 3 grid round the tile it gives:

  • tap a square to cycle what that neighbour must be: nothing (anything goes), a green arrow (this rule tile is there), a red ✕ (it isn't: empty, or another tile);
  • tap the tile strip next to the grid to choose the tile the rule gives. Choose several and each cell gets one of them at random; a cell keeps its pick when you paint round it.

The rules are checked top to bottom and the first one that matches wins, so put the most particular ones first (a corner, nothing above and nothing left, before an edge, nothing above). Use ↑ ↓ to reorder, ⧉ to copy a rule and 🗑 to delete it.

The Ground selected: its rule tile's Default and the rules for the corners and edges

Rules look at all eight neighbours, so diagonals count: an inner corner is this above, this on the left, not this up-left. Every tile a rule gives belongs to the rule tile, so cells painted with it count as this for their neighbours.

In data (scripts, Set component, the AI assistant), a rule tile is an auto tile set with kind: "rule", tiles = the Default first, and rules: [{ match: [up-left, up, up-right, left, right, down-left, down, down-right], tiles: [...] }], where 0 = anything, 1 = this, 2 = not this.

Animated tiles​

Water, torches, lava, blinking lights: a tile can play a short animation. The frames are tiles of the same sheet, so there is nothing new to draw.

In the Tilemap card, under Animated tiles:

  1. Tap + Animated tile.
  2. Tap the tiles in the order they should play (for example the three water frames). Tap ↩ Undo to take the last one back. You need at least two. Tap Done.
  3. Name it. It plays at 6 frames per second; change the number in its row to speed it up or slow it down.
Tap the frames in the order they play
Tap the frames in the order they play

The animation's row shows all its frames in the order they play, and in the palette every tile that belongs to an animation has a small ▶ mark, so you can always see which tiles are animated and what plays. Now every cell that shows one of those tiles plays the animation, whichever frame you painted it with. Paint with the first frame as usual. All cells with the same animation play in step. Turn on 🎲 Offset in the animation's row to start every cell at its own frame, so a row of torches flickers out of step. The offset is fixed per cell, so it looks the same every time. Delete an animation with 🗑 and the cells go back to showing their own tile.

  • The animation plays in the game. In the editor the tilemap shows the first frame, so painting doesn't redraw the screen all the time (this saves battery).
  • What a tile does (solid, one-way, climbable) follows the tile number you painted, not the frame being shown. Give the animation's first frame the behavior you want.
  • Animated cells cost very little: only their pictures change, the tilemap is not rebuilt.
  • If you edit the tile sheet (insert, delete or move frames), the animations are renumbered with the rest. An animation that lost one of its frames is removed.
  • setTile in events and scripts works with them: paint a cell with a frame of an animation and it plays.

Layers​

Every Tilemap object is a layer: Background, Ground, Foreground. In the Tilemap card, a row of buttons lists all the tilemaps of the scene. Tap one to select it and paint on it, with Paint tiles staying on while you switch. + Layer adds a new tilemap next to the current one with the same tile sheet, tile size, edges, auto tiles, animated tiles and tile kinds, empty, drawn one Sort order above the highest layer. It has no Collider, so it is scenery: give it a lower Sort order to put it behind the player, or a higher one to draw it in front (grass over the player's feet, tree tops). Add a Collider to a layer that should block.

Climbing​

A Platformer with Climb switched on can climb the tiles you marked Climbable: press up or down next to a ladder to grab it, up / down to climb, and let go with left / right (to step onto a platform at the top) or Jump. Stack climbable tiles for the ladder, and put a one-way platform tile beside its top so the hero can step onto it. Objects tagged ladder work the same, for a ladder that is one picture.

Settings​

SettingWhat it does
Tile sheetThe picture with the tiles.
Tile size (m)How big one tile is in the world. 1 = one meter per tile.
Color / OpacityTint and fade the whole tilemap.
Sort orderHigher draws in front of lower, like sprites. Use it to put a scenery tilemap behind the level.
EdgesSmooth blends pixels; Pixel (hard) keeps pixel art crisp.
MaterialLit shows 2D lights; Unlit leaves the tiles as they are.
Normal mapA second picture laid out like the tile sheet, with the tiles' bumps, for 2D lights with Normal Maps.
Collider depth (m)How thick the collision boxes are.
ClearEmpty the whole map.

Cells are counted in tiles from the object's position: cell (0, 0) is the square from the position up and to the right (X right, Y up). Negative numbers go left and down.

Events and scripts​

BlockWhat it does
Paint tile … at cell (x, y)Puts a tile in one cell. The collision follows at once.
Erase the tile at cell (x, y)Empties one cell.

In scripts, on the tilemap object:

entity.setTile(3, 0, 2); // cell (3, 0) becomes tile 2
entity.getTile(3, 0); // 2 (-1 when the cell is empty)
entity.removeTile(3, 0); // empty again
const p = game.find('Player').getWorldPosition();
const c = entity.cellAt(p.x, p.y); // { x, y }: the cell at a world position

A negative tile number erases the cell. Use cellAt to find the cell under a hero or a tap: "if the cell under the hero is a spike tile, hurt it".

Ideas​

  • Doors and blocks: a switch calls removeTile on a wall, and the way is open.
  • Digging: on tap, find the cell with cellAt and erase it.
  • Two layers: tap + Layer and give it a lower Sort order for scenery that does not block.