godot-tilemap-mastery

$npx mdskill add thedivergentai/GD-Agentic-Skills/godot-tilemap-mastery

Master TileMapLayer and TileSet for efficient 2D level design.

  • Avoids common pitfalls like unbatched set_cell calls and coordinate mixing.
  • Depends on Godot 4.7+ TileMapLayer, TileSet, terrain sets, and physics layers.
  • Recommends terrain autotiling, chunk batching, and custom data for dynamic tiles.
  • Delivers patterns for runtime manipulation, navigation integration, and destructible tiles.

SKILL.md

.github/skills/godot-tilemap-masteryView on GitHub ↗
---
name: godot-tilemap-mastery
description: "Expert blueprint for TileMapLayer and TileSet systems for efficient 2D level design. Covers terrain autotiling, physics layers, custom data, navigation integration, and runtime manipulation. Use when building grid-based levels OR implementing destructible tiles. Keywords TileMapLayer, TileSet, terrain, autotiling, atlas, physics layer, custom data."
---

## Godot 4.7 Baseline

- Expert patterns in this skill target **Godot 4.7+** (stable, 2026-06-18).
- Consult the [Godot 4.7 migration guide](https://docs.godotengine.org/en/4.7/tutorials/migrating/upgrading_to_godot_4.7.html) when upgrading projects from 4.6.
- **NEVER** assume 4.6 defaults (stretch mode, audio area_mask, RichTextLabel percent flags) without checking 4.7 migration notes.

# TileMap Mastery

TileMapLayer routing + trade-offs — not TileSet editor Steps 1–3 tutorials (see Official Docs).

## NEVER Do in TileMaps

- **NEVER call `set_cell()` in huge loops without batching** — Prefer terrain connect, patterns, or chunk batchers.
- **NEVER forget `source_id` in `set_cell`** — Wrong overload → crash or silent miss.
- **NEVER mix world coords with tile coords** — Always `local_to_map` / `map_to_local`.
- **NEVER hand-paint organic blobs when terrains exist** — Use terrain sets + `set_cells_terrain_connect`.
- **NEVER put dynamic actors in the TileMap** — Enemies/pickups are nodes; tiles are geometry / destructible cells.
- **NEVER spam `get_cell_tile_data()` every physics frame** — Cache metadata ([fast_metadata_cache.gd](scripts/fast_metadata_cache.gd)).

---

## Decision Tree: How to Write Cells

| Goal | Prefer | Script | Trade-off |
|------|--------|--------|-----------|
| Organic ground / roads / rivers | **Terrain autotile** | [terrain_autotile.gd](scripts/terrain_autotile.gd) / [terrain_path_painter.gd](scripts/terrain_path_painter.gd) | Setup cost in TileSet; fastest designer iteration |
| Prefab rooms / houses / stamps | **TileMapPattern** | [tile_pattern_stamper.gd](scripts/tile_pattern_stamper.gd) | Great for procgen pieces; less flexible per-cell |
| Sparse / precise edits | **`set_cell`** | — | Fine for few cells; bad for thousands/frame |
| Huge streaming worlds | **Chunks** | [tilemap_chunking.gd](scripts/tilemap_chunking.gd) / [procedural_chunk_batcher.gd](scripts/procedural_chunk_batcher.gd) / [tilemap_data_manager.gd](scripts/tilemap_data_manager.gd) | Indirection + load boundaries |
| Destructible dig/break | Custom data HP | [destructible_tile_logic.gd](scripts/destructible_tile_logic.gd) | Must refresh nav/physics after edits |
| Gameplay queries (friction/hazard) | Custom data + cache | [gameplay_data_query.gd](scripts/gameplay_data_query.gd) / [fast_metadata_cache.gd](scripts/fast_metadata_cache.gd) | Cache invalidation on set_cell |
| Nav after edits | Runtime nav fix | [nav_mesh_teleport_fix.gd](scripts/nav_mesh_teleport_fix.gd) | Costly if every cell; batch rebuilds |
| One-way / physics layers | TileSet physics | [physics_shape_interaction.gd](scripts/physics_shape_interaction.gd) | Align with CharacterBody masks |
| Iso / multi-floor sort | Y-sort layers | [sorting_Z_layering.gd](scripts/sorting_Z_layering.gd) | Parent + all layers need y_sort |
| Legacy TileMap → layers | Migration | [tilemap_layer_v43_upgrade.gd](scripts/tilemap_layer_v43_upgrade.gd) | One-time upgrade aid |

Editor atlas/physics paint setup: Official Documentation in Reference — **Do NOT** reload Steps 1–3 / flood_fill tutorials from this skill body.

## Available Scripts (single index + MANDATORY triggers)

| Task | MANDATORY script(s) |
|------|---------------------|
| Serialize / large world data | [tilemap_data_manager.gd](scripts/tilemap_data_manager.gd) |
| Runtime terrain paths | [terrain_path_painter.gd](scripts/terrain_path_painter.gd) / [terrain_autotile.gd](scripts/terrain_autotile.gd) |
| Destructible tiles | [destructible_tile_logic.gd](scripts/destructible_tile_logic.gd) |
| Custom data gameplay reads | [gameplay_data_query.gd](scripts/gameplay_data_query.gd) (+ [fast_metadata_cache.gd](scripts/fast_metadata_cache.gd) if hot) |
| Procedural bulk place | [procedural_chunk_batcher.gd](scripts/procedural_chunk_batcher.gd) |
| Chunk stream in/out | [tilemap_chunking.gd](scripts/tilemap_chunking.gd) |
| Pattern stamp prefabs | [tile_pattern_stamper.gd](scripts/tile_pattern_stamper.gd) |
| Nav repair after edits | [nav_mesh_teleport_fix.gd](scripts/nav_mesh_teleport_fix.gd) |
| One-way / physics layer ops | [physics_shape_interaction.gd](scripts/physics_shape_interaction.gd) |
| Y-sort / Z layering | [sorting_Z_layering.gd](scripts/sorting_Z_layering.gd) |
| 4.3+ multi-layer upgrade | [tilemap_layer_v43_upgrade.gd](scripts/tilemap_layer_v43_upgrade.gd) |

## Expert Trade-offs (routing only)

- **Isometric Y-sort:** enable `y_sort_enabled` on parent and each TileMapLayer; tune `y_sort_origin` on tall tiles — see [sorting_Z_layering.gd](scripts/sorting_Z_layering.gd).
- **Procgen:** stamp patterns or batch terrain; avoid per-cell `set_cell` storms — [tile_pattern_stamper.gd](scripts/tile_pattern_stamper.gd) / [procedural_chunk_batcher.gd](scripts/procedural_chunk_batcher.gd).
- **Diff / save deltas:** compare `get_used_cells()` source_id/atlas between layers; persist deltas via [tilemap_data_manager.gd](scripts/tilemap_data_manager.gd) rather than full maps when possible.


## Deep recipes (on demand)

> LLM-ignorance rule: if a general agent would not know it before reading, it lives here or in `scripts/` — never delete, only move.

| Topic | Reference |
|-------|-----------|
| TileSet editor steps | [tileset-editor-setup.md](references/tileset-editor-setup.md) |
| Runtime APIs + flood/terrain | [runtime-tile-patterns.md](references/runtime-tile-patterns.md) |
| Iso / patterns / diff | [expert-tilemap-architectures.md](references/expert-tilemap-architectures.md) |

## Reference

> Progressive disclosure: open Official Documentation links only when researching a specific API; load Related Skills when routing to a peer domain — do not preload the whole lattice.

### Official Documentation
- [Using TileMaps](https://docs.godotengine.org/en/stable/tutorials/2d/using_tilemaps.html) — TileMapLayer workflow, layers, runtime `set_cell` / terrain painting, and when multiple layers beat a single legacy TileMap.
- [Using TileSets](https://docs.godotengine.org/en/stable/tutorials/2d/using_tilesets.html) — atlas sources, terrains, physics/navigation/custom data layers painted in the TileSet editor.
- [TileMapLayer](https://docs.godotengine.org/en/stable/classes/class_tilemaplayer.html) — cell APIs, terrain connect, patterns, coordinate conversion, and runtime tile-data updates.
- [TileSet](https://docs.godotengine.org/en/stable/classes/class_tileset.html) — physics/terrain/custom-data layer definitions shared by every TileMapLayer that references the resource.
- [TileSetAtlasSource](https://docs.godotengine.org/en/stable/classes/class_tilesetatlassource.html) — atlas grid, alternatives, and per-tile TileData that drive collision and metadata.
- [TileData](https://docs.godotengine.org/en/stable/classes/class_tiledata.html) — custom data, physics polygons, navigation polygons, and `y_sort_origin` used at query time.
- [TileMapPattern](https://docs.godotengine.org/en/stable/classes/class_tilemappattern.html) — capture/stamp multi-tile prefabs without per-cell `set_cell` loops.
- [Collision shapes (2D)](https://docs.godotengine.org/en/stable/tutorials/physics/collision_shapes_2d.html) — shape choices and one-way collision patterns that TileSet physics layers expose to CharacterBody2D.
- [Navigation introduction (2D)](https://docs.godotengine.org/en/stable/tutorials/navigation/navigation_introduction_2d.html) — how tile navigation polygons feed NavigationRegion2D / NavigationAgent2D after edits.
- [Canvas layers](https://docs.godotengine.org/en/stable/tutorials/2d/canvas_layers.html) — z-index / CanvasLayer separation for ground, decoration, and roof TileMapLayers.
- [Background loading](https://docs.godotengine.org/en/stable/tutorials/io/background_loading.html) — threaded ResourceLoader patterns for streaming chunk TileSets / tilemap scenes without hitch spikes.

### Related Skills

#### Prerequisites
- [godot-project-foundations](https://github.com/thedivergentai/gd-agentic-skills/blob/main/skills/godot-project-foundations/SKILL.md) — scene tree, resources, and import layout before authoring TileSet atlases and multi-layer level scenes.
- [godot-gdscript-mastery](https://github.com/thedivergentai/gd-agentic-skills/blob/main/skills/godot-gdscript-mastery/SKILL.md) — typed Vector2i APIs, caching patterns, and signal-up/call-down structure used in runtime tile managers.
- [godot-2d-physics](https://github.com/thedivergentai/gd-agentic-skills/blob/main/skills/godot-2d-physics/SKILL.md) — collision layers/masks and StaticBody2D-equivalent behavior that TileMapLayer physics layers participate in.

#### Complements
- [godot-characterbody-2d](https://github.com/thedivergentai/gd-agentic-skills/blob/main/skills/godot-characterbody-2d/SKILL.md) — `move_and_slide` against tile colliders, one-way platforms, and floor/wall queries over TileMapLayer geometry.
- [godot-navigation-pathfinding](https://github.com/thedivergentai/gd-agentic-skills/blob/main/skills/godot-navigation-pathfinding/SKILL.md) — NavigationAgent2D / region updates when destructible or procedural tiles change walkable polygons.
- [godot-camera-systems](https://github.com/thedivergentai/gd-agentic-skills/blob/main/skills/godot-camera-systems/SKILL.md) — Camera2D limits and follow radii that drive chunk load/unload around the player.
- [godot-adapt-3d-to-2d](https://github.com/thedivergentai/gd-agentic-skills/blob/main/skills/godot-adapt-3d-to-2d/SKILL.md) — isometric / Y-sort depth tricks that pair with `TILE_SHAPE_ISOMETRIC` and multi-floor TileMapLayers.
- [godot-scene-management](https://github.com/thedivergentai/gd-agentic-skills/blob/main/skills/godot-scene-management/SKILL.md) — packing and swapping chunk scenes so large tile worlds stream without orphaned layers.
- [godot-performance-optimization](https://github.com/thedivergentai/gd-agentic-skills/blob/main/skills/godot-performance-optimization/SKILL.md) — batching, cache budgets, and profiler checks when `set_cell` / custom-data queries dominate frame time.

#### Downstream / consumers
- [godot-procedural-generation](https://github.com/thedivergentai/gd-agentic-skills/blob/main/skills/godot-procedural-generation/SKILL.md) — noise/BSP/WFC generators that write cells via terrain connect, patterns, or chunk batchers.
- [godot-genre-platformer](https://github.com/thedivergentai/gd-agentic-skills/blob/main/skills/godot-genre-platformer/SKILL.md) — precision platformer levels built from TileSet physics, one-ways, and hazard custom data.
- [godot-genre-metroidvania](https://github.com/thedivergentai/gd-agentic-skills/blob/main/skills/godot-genre-metroidvania/SKILL.md) — interconnected room grids, ability gates, and map revelation layered on TileMapLayer chunks.
- [godot-genre-sandbox](https://github.com/thedivergentai/gd-agentic-skills/blob/main/skills/godot-genre-sandbox/SKILL.md) — diggable/buildable 2D worlds that treat TileMapLayer as the editable terrain backend.
- [godot-monte-carlo-balancer](https://github.com/thedivergentai/gd-agentic-skills/blob/main/skills/godot-monte-carlo-balancer/SKILL.md) — simulate hazard density, destructible HP, and traversal cost encoded in tile custom data before shipping maps.

#### Master
- [godot-master](https://github.com/thedivergentai/gd-agentic-skills/blob/main/skills/godot-master/SKILL.md) — library router and mirrored module entry for cross-skill discovery.

More from thedivergentai/GD-Agentic-Skills

SkillDescription
godot-2d-animationExpert patterns for 2D animation in Godot using AnimatedSprite2D and skeletal cutout rigs. Use when implementing sprite frame animations, procedural animation (squash/stretch), cutout bone hierarchies, or frame-perfect timing systems. Trigger keywords: AnimatedSprite2D, SpriteFrames, animation_finished, animation_looped, frame_changed, frame_progress, set_frame_and_progress, cutout animation, skeletal 2D, Bone2D, procedural animation, animation state machine, advance(0).
godot-2d-physicsExpert patterns for Godot 2D physics including collision layers/masks, Area2D triggers, raycasting, and PhysicsDirectSpaceState2D queries. Use when implementing collision detection, trigger zones, line-of-sight systems, or manual physics queries. Trigger keywords: CollisionShape2D, CollisionPolygon2D, collision_layer, collision_mask, set_collision_layer_value, set_collision_mask_value, Area2D, body_entered, body_exited, RayCast2D, force_raycast_update, PhysicsPointQueryParameters2D, PhysicsShapeQueryParameters2D, direct_space_state, move_and_collide, move_and_slide.
godot-3d-lightingExpert patterns for Godot 3D lighting including DirectionalLight3D shadow cascades, OmniLight3D attenuation, SpotLight3D projectors, VoxelGI vs SDFGI, and LightmapGI baking. Use when implementing realistic 3D lighting, shadow optimization, global illumination, or light probes. Trigger keywords: DirectionalLight3D, OmniLight3D, SpotLight3D, shadow_enabled, directional_shadow_mode, directional_shadow_split, omni_range, omni_attenuation, spot_range, spot_angle, VoxelGI, SDFGI, LightmapGI, ReflectionProbe, Environment, WorldEnvironment.
godot-3d-materialsExpert patterns for Godot 3D PBR materials using StandardMaterial3D including albedo, metallic/roughness workflows, normal maps, ORM texture packing, transparency modes, and shader conversion. Use when creating realistic 3D surfaces, PBR workflows, or material optimization. Trigger keywords: StandardMaterial3D, BaseMaterial3D, albedo_texture, metallic, metallic_texture, roughness, roughness_texture, normal_texture, normal_enabled, orm_texture, transparency, alpha_scissor, alpha_hash, cull_mode, ShaderMaterial, shader parameters.
godot-3d-world-buildingExpert patterns for 3D level design using GridMap with MeshLibrary, CSG constructive solid geometry, occlusion, and runtime GridMap builders. Use when building 3D levels, modular tilesets, or BSP-style geometry. For sky/fog/Environment recipes, route to godot-3d-lighting. Trigger keywords: GridMap, MeshLibrary, set_cell_item, get_cell_item, map_to_local, local_to_map, CSGCombiner3D, CSGBox3D, CSGSphere3D, CSGPolygon3D, OccluderInstance3D, bake CSG.
godot-ability-systemExpert patterns for RPG/action ability systems including cooldown strategies, combo systems, ability chaining, skill trees with prerequisites, upgrade paths, and resource management. Use when implementing unlockable abilities, character progression, or complex skill systems. Trigger keywords: PlayerAbility, AbilityManager, cooldown, SkillTree, SkillNode, prerequisites, can_use, execute, ComboSystem, ability_chain, global_cooldown, charge_system, upgrade_path.
godot-adapt-2d-to-3dExpert patterns for migrating 2D games to 3D including node type conversions, camera systems (third-person, first-person, orbit), physics layer migration, sprite-to-model art pipeline, and control scheme adaptations. Use when porting 2D projects to 3D or adding 3D elements. Trigger keywords: CharacterBody2D to CharacterBody3D, Area2D to Area3D, Camera2D to Camera3D, Vector2 to Vector3, collision_layer migration, sprite to MeshInstance3D, 2D to 3D conversion.
godot-adapt-3d-to-2dExpert patterns for simplifying 3D games to 2D including dimension reduction strategies, 2.5D fake-depth, isometric ports, camera flattening, physics conversion, 3D-to-sprite art pipeline, and control simplification. Use when porting 3D to 2D, building 2.5D / isometric / fake-depth gameplay, creating 2D versions for mobile, or prototyping. Trigger keywords: CharacterBody3D to CharacterBody2D, Camera3D to Camera2D, Vector3 to Vector2, flatten Z-axis, 2.5D, isometric, fake depth, Y-sort, simulated Z, orthogonal projection, 3D to sprite conversion, performance optimization.
godot-adapt-desktop-to-mobileExpert patterns for porting desktop games to mobile including touch control schemes (virtual joystick, gesture detection), UI scaling for small screens, performance optimization for mobile GPUs, battery life management, and platform-specific features. Use when creating mobile ports or cross-platform mobile builds. Trigger keywords: TouchScreenButton, virtual_joystick, gesture_detector, InputEventScreenTouch, InputEventScreenDrag, mobile_optimization, battery_saving, adaptive_performance, MOBILE_ENABLED.
godot-adapt-mobile-to-desktopExpert patterns for scaling mobile games to desktop including mouse/keyboard controls, increased resolution and graphical fidelity, expanded UI layouts, settings menus, window management, and platform-specific features. Use when creating desktop ports or cross-platform releases. Trigger keywords: mouse_controls, keyboard_shortcuts, resolution_scaling, graphics_settings, fullscreen_toggle, window_modes, Steam_integration, desktop_optimization.