This page documents the tile-based map system in Godot, covering TileMap, TileMapLayer, TileSet, TileSetAtlasSource, TileData, and related classes. This system lives under the Scene System (see page 4); for the 2D rendering pipeline that draws tiles, see page 7
The TileMap system provides grid-based 2D maps. Tiles are defined in a shared TileSet resource and placed into one or more TileMapLayer nodes. Each cell on a layer references a tile by three IDs: source_id, atlas_coords, and alternative_tile.
Deprecation note:
TileMapis deprecated as of Godot 4.x. New projects should use individualTileMapLayernodes directly. TheTileMapnode now emits a configuration warning recommending migration. See the TileMap → TileMapLayer section below.
Sources: scene/register_scene_types.cpp, scene/2d/node_2d.cpp
Class Relationship Overview
Sources: scene/register_scene_types.cpp101-150 scene/2d/node_2d.h31-100 scene/resources/atlas_texture.h37-60
TileMapCellEvery occupied cell is stored as a TileMapCell. It is a compact structure used to identify which tile from the TileSet is placed at a specific coordinate.
| Field | Type | Description |
|---|---|---|
source_id | int16_t | Identifies the TileSetSource within the TileSet |
coord_x, coord_y | int16_t | Atlas coordinates identifying the tile within the source |
alternative_tile | int16_t | Alternative tile variant (rotation/flip flags or scene index) |
An invalid/empty cell typically uses -1 for these IDs.
Sources: scene/resources/atlas_texture.cpp33-80
TileMapLayerTileMapLayer is the modern node class for a single tile layer. It inherits from Node2D and CanvasItem, allowing it to handle its own transforms and rendering calls to the RenderingServer.
Like all CanvasItem nodes, TileMapLayer uses the RenderingServer to draw. It calculates its local transform based on the TileSet grid properties.
Sources: scene/2d/node_2d.cpp139-146 scene/main/canvas_item.h35-100
TileSetTileSet defines the library of tiles. It contains TileSetSource objects, which can be textures (atlases) or scene collections.
TileSet supports multiple functional layers that apply to all tiles:
PhysicsServer2D.NavigationServer2D.Sources: scene/register_scene_types.cpp145-147 servers/register_server_types.cpp87-98
Source Type Hierarchy
Sources: core/register_core_types.cpp150-160 scene/resources/texture.h41-84
TileSetAtlasSourceAn atlas source uses a Texture2D (such as a CompressedTexture2D or ImageTexture) and slices it into a grid. Each tile in the grid can have TileData associated with it.
TileSetScenesCollectionSourceThis source allows grid cells to represent PackedScene resources. When the map is instantiated, the system spawns these scenes as child nodes.
Sources: scene/resources/texture.cpp37-121 scene/register_scene_types.cpp150-155
TileDataTileData holds the properties for a specific tile. This includes visual properties (modulate, Z-index) and functional properties (collision polygons, navigation).
| Property | Description |
|---|---|
modulate | The color applied to the tile texture during draw_rect_region. |
z_index | The rendering priority relative to other items in the same CanvasLayer. |
terrain | The terrain ID used by the auto-tiling algorithms. |
Sources: scene/resources/texture.cpp89-108 scene/main/canvas_layer.cpp35-80
Internal Update Sequence
Tiles are rendered via the CanvasItem API. When a cell changes, the layer triggers a redraw or updates its internal representation in the physics/navigation servers.
Sources: scene/resources/texture.cpp103-108 scene/2d/node_2d.cpp139-146 servers/register_server_types.cpp93-98
TileMap to TileMapLayer {#migration}TileMap is now a legacy wrapper. The engine encourages moving to TileMapLayer nodes for better performance and clearer scene trees.
Deprecated TileMap Call | New TileMapLayer Equivalent |
|---|---|
set_cell(layer_index, coords, ...) | set_cell(coords, ...) on the specific layer node |
get_cell_source_id(layer, coords) | get_cell_source_id(coords) |
Sources: scene/register_scene_types.cpp101-110 scene/2d/node_2d.h31-50
Refresh this wiki
This wiki was recently refreshed. Please wait 3 days to refresh again.