FAQ¶
Short answers to the questions that come up most. Each one links to the page with the full story. For something that is broken rather than unclear, start with Troubleshooting.
Scripting¶
How do I remove a tile?¶
See Scripting.
I called SetTile, SetTileData or Erase and the tilemap did not change¶
Writes only change the stored data. Call tilemap.UpdateMesh() after your last write, or
tilemap.UpdateMeshImmediate() if you need the result before your code continues. From an
editor script, always use UpdateMeshImmediate.
If it still does not change, check AllowPaintingOutOfBounds. When it is off, writes outside the
map bounds are ignored. See When the tilemap updates.
My script says the type or namespace STETilemap could not be found (CS0246)¶
Add this line at the top of the file:
The component is called STETilemap. Tilemap on its own is Unity's built-in class, in
UnityEngine.Tilemaps.
How do I get the centre of a tile?¶
TilemapUtils.GetGridWorldPos(tilemap, gridX, gridY) gives the world position of the cell's
centre. TilemapUtils.GetTileCenterPosition(tilemap, gridX, gridY) gives it in the tilemap's
local space. See Positions and the Mouse.
How do I get the grid cell under the mouse?¶
TilemapUtils.GetMouseGridX(tilemap, camera) and GetMouseGridY(tilemap, camera). With the
Input System package as your only input handling, use TilemapUtils.ScreenToLocalPosition
instead. See The cell under the mouse.
How do I make a tile a separate GameObject?¶
Make a prefab with a SpriteRenderer and a TileObjectBehaviour, and assign it to the tile in
the Tile Properties window, in the prefab section. Every cell painted with that tile gets an
instance that looks like the tile and can carry its own components. See
Tile Prefabs.
How do I know which tilemap I collided with?¶
The colliders belong to hidden child objects of the tilemap, so walk up from the collider:
How do I know which tile I collided with?¶
Take the contact point, move it a tenth of a cell against the contact normal so it lands inside the tile rather than on its edge, and convert it to a cell. Collisions has a helper that works for 2D and 3D.
How do I know if a cell is passable?¶
Check whether the cell holds a tile with a collider:
Tile tile = tilemap.GetTile(gridX, gridY);
bool blocked = tile != null && tile.collData.type != eTileCollider.None;
The included A* pathfinder uses the same test across a whole tilemap group. See Pathfinding.
Tilesets¶
How do I add tiles to a tileset without breaking my maps?¶
Maps store tile ids, and a tile's id is its position in the atlas, counted row by row from the top
left. Adding a column makes every row longer and renumbers every tile after the first row. Add
rows at the bottom of the atlas instead, keep the width, and slice again. When the slice asks
Keep previous tile properties?, answer Yes so colliders, parameters, prefabs and autotiling groups stay with
their ids. See Tilesets.
My atlas is larger than 2048 pixels and looks blurry or scaled down¶
Unity imports textures with a Max Size of 2048 by default. Raise it in the atlas texture's
import settings. Check Project Settings > Quality too, where Global Mipmap Limit can halve
texture resolution per quality level.
Tilemaps¶
Tiles flicker or pop in and out where two tilemaps overlap¶
The two tilemaps have the same Sorting Layer and Order in Layer, so Unity has no rule for
which draws on top. Give each tilemap its own Order in Layer in the Renderer tab. See
Renderer.
My character passes through the 2D colliders, or snags between tiles¶
Check these in order:
- An
EdgeCollider2Dis a line with no inside. A fast body can cross it in one physics step. Set the character'sRigidbody2DCollision DetectiontoContinuous. - Collider normals should face out of the solid area. Turn on
Show Collider Normalsin theCollidertab to see them, and useReverse Normalsin the tile's collider editor if a custom shape faces the wrong way. - With
Is Triggeron, or withPolygonCollider2D, the inspector warns that the generated lines can be wrong. For polygons, tickCollider 2D Optimization Disabled, or setCollider Generation MethodtoClipper.
See Colliders.
Painting is slow on a big map¶
Each stroke rebuilds the whole chunk under it, mesh and colliders, and records an undo step. While
you paint a large area, set Collider Type to None and untick Enable Undo under
Advanced Options in the Map tab, then restore both. Version 1.7.7 also made fills, chunk
rebuilds and undo on large maps much faster, so update if you are on an older version. See
How It Works.
The tilemap disappears when I zoom in the scene view¶
The scene view camera is clipping it. Select the tilemap and press F to frame it, which resets
the camera's distance, and work in 2D mode for a 2D map. In the game view, check that the tilemap
is between the camera's near and far clipping planes.