
Godot Tilemap Mastery
- 225 installs
- 454 repo stars
- Updated July 28, 2026
- thedivergentai/gd-agentic-skills
Use godot-tilemap-mastery for development tasks
About
godot-tilemap-mastery: A skill for development. This provides functionality for development workflows.
- godot-tilemap-mastery
Godot Tilemap Mastery by the numbers
- 225 all-time installs (skills.sh)
- +19 installs in the week ending Jul 27, 2026 (Skillselion tracking)
- Ranked #1,726 of 4,347 Backend & APIs skills by installs in the Skillselion catalog
- Data as of Aug 5, 2026 (Skillselion catalog sync)
npx skills add https://github.com/thedivergentai/gd-agentic-skills --skill godot-tilemap-masteryAdd your badge
Show developers this skill is listed on Skillselion. Paste this into your README.
| Installs | 225 |
|---|---|
| repo stars | ★ 454 |
| Last updated | July 28, 2026 |
| Repository | thedivergentai/gd-agentic-skills ↗ |
What it does
Use godot-tilemap-mastery for development tasks
Files
TileMap Mastery
TileMapLayer grids, TileSet atlases, terrain autotiling, and custom data define efficient 2D level systems.
Available Scripts
tilemap_data_manager.gd
Expert TileMap serialization and chunking manager for large worlds.
terrain_path_painter.gd
Advanced runtime terrain autotiling (Terrains v2) for roads, rivers, and organic paths.
destructible_tile_logic.gd
Pattern for managing tile health and breakage based on Custom Data Layers.
gameplay_data_query.gd
Efficiently reading Custom Data (friction, hazards) to drive character/physics logic.
procedural_chunk_batcher.gd
Optimized procedural generation using bulk tile placement logic for better performance.
sorting_Z_layering.gd
Handling Y-sorting and Z-index layering for 2.5D effects and multi-floor buildings.
physics_shape_interaction.gd
Expert TileMap physics: handling one-way collisions and collision layer management.
nav_mesh_teleport_fix.gd
Runtime navigation updates for dynamic world-shifting and destructible environments.
tile_pattern_stamper.gd
Using TileMapPattern for efficiently "stamping" complex, multi-tile structural pieces.
fast_metadata_cache.gd
Optimization: caching TileData metadata for high-frequency gameplay queries.
tilemap_layer_v43_upgrade.gd
Managing the transition to the Godot 4.3 standard of multiple TileMapLayer nodes.
NEVER Do in TileMaps
- NEVER use set_cell() in loops without batching — 1000 tiles ×
set_cell()= 1000 individual function calls = slow. Useset_cells_terrain_connect()for bulk OR cache changes, apply once. - NEVER forget source_id parameter —
set_cell(pos, atlas_coords)without source_id? Wrong overload = crash OR silent failure. Useset_cell(pos, source_id, atlas_coords). - NEVER mix tile coordinates with world coordinates —
set_cell(mouse_position)withoutlocal_to_map()? Wrong grid position. ALWAYS convert:local_to_map(global_pos). - NEVER skip terrain set configuration — Manual tile assignment for organic shapes? 100+ tiles for grass patch. Use
set_cells_terrain_connect()with terrain sets for autotiling. - NEVER use TileMap for dynamic entities — Enemies/pickups as tiles? No signals, physics, scripts. Use Node2D/CharacterBody2D, reserve TileMap for static/destructible geometry.
- NEVER query get_cell_tile_data() in _physics_process — Every frame tile data lookup? Performance tank. Cache tile data in dictionary:
tile_cache[pos] = get_cell_tile_data(pos).
---
Step 1: Create TileSet Resource
1. Create a TileMapLayer node 2. In Inspector: TileSet → New TileSet 3. Click TileSet to open bottom TileSet editor
Step 2: Add Tile Atlas
1. In TileSet editor: + → Atlas 2. Select your tile sheet texture 3. Configure grid size (e.g., 16x16 pixels per tile)
Step 3: Add Physics, Collision, Navigation
# Each tile can have:
# - Physics Layer: CollisionShape2D for each tile
# - Terrain: Auto-tiling rules
# - Custom Data: Arbitrary propertiesAdd collision to tiles: 1. Select tile in TileSet editor 2. Switch to "Physics" tab 3. Draw collision polygon
Using TileMapLayer
Basic Tilemap Setup
extends TileMapLayer
func _ready() -> void:
# Set tile at grid coordinates (x, y)
set_cell(Vector2i(0, 0), 0, Vector2i(0, 0)) # source_id, atlas_coords
# Get tile at coordinates
var atlas_coords := get_cell_atlas_coords(Vector2i(0, 0))
# Clear tile
erase_cell(Vector2i(0, 0))Runtime Tile Placement
extends TileMapLayer
func _input(event: InputEvent) -> void:
if event is InputEventMouseButton and event.pressed:
var global_pos := get_global_mouse_position()
var tile_pos := local_to_map(global_pos)
# Place grass tile (assuming source_id=0, atlas=(0,0))
set_cell(tile_pos, 0, Vector2i(0, 0))Flood Fill Pattern
func flood_fill(start_pos: Vector2i, tile_source: int, atlas_coords: Vector2i) -> void:
var cells_to_fill: Array[Vector2i] = [start_pos]
var original_tile := get_cell_atlas_coords(start_pos)
while cells_to_fill.size() > 0:
var current := cells_to_fill.pop_back()
if get_cell_atlas_coords(current) != original_tile:
continue
set_cell(current, tile_source, atlas_coords)
# Add neighbors
for dir in [Vector2i.UP, Vector2i.DOWN, Vector2i.LEFT, Vector2i.RIGHT]:
cells_to_fill.append(current + dir)Terrain Auto-Tiling
Setup Terrain Set
1. In TileSet editor: Terrains tab 2. Add Terrain Set (e.g., "Ground") 3. Add Terrain (e.g., "Grass", "Dirt") 4. Assign tiles to terrain by painting them
Use Terrain in Code
extends TileMapLayer
func paint_terrain(start: Vector2i, end: Vector2i, terrain_set: int, terrain: int) -> void:
for x in range(start.x, end.x + 1):
for y in range(start.y, end.y + 1):
set_cells_terrain_connect(
[Vector2i(x, y)],
terrain_set,
terrain,
false # ignore_empty_terrains
)Multiple Layers Pattern
# Scene structure:
# Node2D (Level)
# ├─ TileMapLayer (Ground)
# ├─ TileMapLayer (Decoration)
# └─ TileMapLayer (Collision)
# Each layer can have different:
# - Rendering order (z_index)
# - Collision layers/masks
# - Modulation (color tint)Physics Integration
Enable Physics Layer
1. TileSet editor → Physics Layers 2. Add physics layer 3. Assign collision shapes to tiles
Check collision from code:
func _physics_process(delta: float) -> void:
# TileMapLayer acts as StaticBody2D
# CharacterBody2D.move_and_slide() automatically detects tilemap collision
passOne-Way Collision Tiles
# In TileSet physics layer settings:
# - Enable "One Way Collision"
# - Set "One Way Collision Margin"
# Character can jump through from belowCustom Tile Data
Define Custom Data Layer
1. TileSet editor → Custom Data Layers 2. Add property (e.g., "damage_per_second: int") 3. Set value for specific tiles
Read Custom Data
func get_tile_damage(tile_pos: Vector2i) -> int:
var tile_data := get_cell_tile_data(tile_pos)
if tile_data:
return tile_data.get_custom_data("damage_per_second")
return 0Performance Optimization
Use TileMapLayer Groups
# Static geometry: Single large TileMapLayer
# Dynamic tiles: Separate layer for runtime changesChunking for Large Worlds
# Split world into multiple TileMapLayer nodes
# Load/unload chunks based on player position
const CHUNK_SIZE := 32
func load_chunk(chunk_coords: Vector2i) -> void:
var chunk_name := "Chunk_%d_%d" % [chunk_coords.x, chunk_coords.y]
var chunk := TileMapLayer.new()
chunk.name = chunk_name
chunk.tile_set = base_tileset
add_child(chunk)
# Load tiles for this chunk...Navigation Integration
Setup Navigation Layer
1. TileSet editor → Navigation Layers 2. Add navigation layer 3. Paint navigation polygons on tiles
Use with NavigationAgent2D:
# Navigation automatically created from TileMap
# NavigationAgent2D.get_next_path_position() works immediatelyBest Practices
1. Organize TileSet by Purpose
TileSet Layers:
- Ground (terrain=grass, dirt, stone)
- Walls (collision + rendering)
- Decoration (no collision, overlay)Available Scripts
MANDATORY: Read before implementing terrain systems or runtime placement.
terrain_autotile.gd
Runtime terrain autotiling with set_cells_terrain_connect batching and validation.
tilemap_chunking.gd
Chunk-based TileMap management with batched updates - essential for large procedural worlds.
2. Use Terrain for Organic Shapes
# ✅ Good - smooth terrain transitions
set_cells_terrain_connect(tile_positions, 0, 0)
# ❌ Bad - manual tile assignment for organic shapes
for pos in positions:
set_cell(pos, 0, Vector2i(0, 0))3. Layer Z-Index Management
# Background layers
$Background.z_index = -10
# Ground layer
$Ground.z_index = 0
# Foreground decoration
$Foreground.z_index = 10Common Patterns
Destructible Tiles
func destroy_tile(world_pos: Vector2) -> void:
var tile_pos := local_to_map(world_pos)
var tile_data := get_cell_tile_data(tile_pos)
if tile_data and tile_data.get_custom_data("destructible"):
erase_cell(tile_pos)
# Spawn particle effect, drop items, etc.Tile Highlighting
@onready var highlight_layer: TileMapLayer = $HighlightLayer
func highlight_tile(tile_pos: Vector2i) -> void:
highlight_layer.clear()
highlight_layer.set_cell(tile_pos, 0, Vector2i(0, 0))Expert TileMap Architectures
1. Isometric TileMap (Z-Sorting / Y-Sorting)
To master isometric rendering in Godot 4.x, configure the TileSet with TILE_SHAPE_ISOMETRIC. To ensure correct depth-sorting between tiles and dynamic entities (like players), enable y_sort_enabled on all TileMapLayer nodes and their mutual Node2D parent. Use y_sort_origin on TileData to precisely tune the sorting pivot for tall objects.
class_name IsometricMapOrchestrator extends Node2D
## Configures multiple TileMapLayers for isometric Y-sorting.
@export var ground: TileMapLayer
@export var objects: TileMapLayer
func _ready() -> void:
# Enable global Y-sorting for this container.
y_sort_enabled = true
# Configure individual layers.
ground.y_sort_enabled = true
objects.y_sort_enabled = true
# Optional: Offset the objects layer to fake height.
objects.y_sort_origin = 16 2. Procedural Generation (TileMapPattern Stamping)
For high-performance procedural generation, use TileMapPattern to store and "stamp" pre-fabricated tile structures. This is significantly faster than calling set_cell() in individual loops and preserves all tile identifiers (source_id, atlas_coords, alternative_tile) perfectly.
class_name TileStamper extends Node
## Efficiently stamps pre-fabricated patterns into a TileMapLayer.
@export var target_layer: TileMapLayer
var _house_pattern: TileMapPattern
func capture_pattern(coords: Array[Vector2i]) -> void:
# Encapsulate a set of cells into a reusable pattern resource.
_house_pattern = target_layer.get_pattern(coords)
func stamp_at(position: Vector2i) -> void:
if _house_pattern:
# Bulk-paste the pattern at the target coordinates.
target_layer.set_pattern(position, _house_pattern)3. Tilemap Diff (Layer Delta Merging)
To implement world-saving or destruction-syncing, calculate the "diff" between two TileMapLayer nodes. By iterating through get_used_cells(), you can identify discrepancies in source_id or atlas_coords and apply only the changes to a target layer, optimizing network or disk I/O.
class_name TileDiffManager extends Node
## Calculates and applies the delta between two TileMapLayers.
func apply_layer_diff(source: TileMapLayer, target: TileMapLayer) -> void:
var source_cells := source.get_used_cells()
for coord in source_cells:
var s_id := source.get_cell_source_id(coord)
var t_id := target.get_cell_source_id(coord)
# If tiles differ, sync the target to the source.
if s_id != t_id:
var atlas := source.get_cell_atlas_coords(coord)
var alt := source.get_cell_alternative_tile(coord)
target.set_cell(coord, s_id, atlas, alt)Reference
Related
- Master Skill: godot-master
# destructible_tile_logic.gd
# Runtime tile modification and destruction [278]
extends TileMapLayer
# Pattern for damaging and breaking tiles based on custom data.
func damage_tile(world_pos: Vector2, damage: float) -> void:
var map_pos = local_to_map(to_local(world_pos))
var data = get_cell_tile_data(map_pos)
if not data: return
# Custom Data Layers allow storing 'HP' or 'Hardness' on the tile itself
var hardness = data.get_custom_data("hardness")
if hardness > 0:
# If the tile is broken, replace with debris or erase
_trigger_break_fx(world_pos)
erase_cell(map_pos)
func _trigger_break_fx(pos: Vector2) -> void:
# Spawn particles or debris debris at the world position
pass
# fast_metadata_cache.gd
# Optimizing Custom Data lookups for massive levels [22, 181]
extends TileMapLayer
# PROBLEM: get_cell_tile_data() can be slow if called thousands of times per frame.
# SOLUTION: Cache semantic metadata in a Dictionary.
var _hazard_cache: Dictionary = {} # Vector2i -> bool
func rebuild_hazard_cache() -> void:
_hazard_cache.clear()
for cell in get_used_cells():
var data = get_cell_tile_data(cell)
if data and data.get_custom_data("is_lava"):
_hazard_cache[cell] = true
func is_cell_hazardous(map_pos: Vector2i) -> bool:
return _hazard_cache.get(map_pos, false)
# gameplay_data_query.gd
# Querying Custom Data Layers for gameplay logic (damage, speed) [181]
extends Node2D
@onready var ground_layer: TileMapLayer = $GroundLayer
func _physics_process(_delta: float) -> void:
# Get tile under player position
var map_pos = ground_layer.local_to_map(ground_layer.to_local(global_position))
var data = ground_layer.get_cell_tile_data(map_pos)
if data:
# Expert: Use string keys from 'Custom Data Layers' setup in TileSet
var surface_friction = data.get_custom_data("friction")
var is_lava = data.get_custom_data("is_lava")
_apply_surface_logic(surface_friction, is_lava)
func _apply_surface_logic(friction: float, lethal: bool) -> void:
# Apply friction to movement or damage if lethal
pass
# nav_mesh_teleport_fix.gd
# Runtime Navigation updates for dynamic TileMap shifts [214]
extends TileMapLayer
# Godot 4 TileMapLayers can automatically bake navigation.
func update_nav_for_hole(map_pos: Vector2i) -> void:
# Erasing a cell with a 'Navigation Layer' configured
# automatically updates the NavigationServer2D mesh.
erase_cell(map_pos)
# If results aren't immediate, force a sync:
# NavigationServer2D.process_frame()
print("Navigation path re-evaluating for hole at: ", map_pos)
# physics_shape_interaction.gd
# Expert TileMap physics and one-way collision logic [146, 160]
extends TileMapLayer
# Each TileMapLayer acts as a single large physics body.
func set_one_way_platform(map_pos: Vector2i, enabled: bool) -> void:
var data = get_cell_tile_data(map_pos)
if data:
# Accessing physics shapes directly via TileData
# Note: Changing this at runtime affects ALL cells using this Tile ID
# To change one specific cell, you must swap to a different Tile ID.
pass
# Recommended Pattern: Use different 'Source IDs' or 'Atlas Coords'
# for collision variants (e.g. solid stone vs. spectral stone).
# procedural_chunk_batcher.gd
# Efficient procedural tile placement using batching [17, 197]
extends TileMapLayer
# PROBLEM: set_cell() is slow in loops.
# SOLUTION: Use an array of data and set in one call (internal C++ optimization).
func generate_flat_chunk(chunk_origin: Vector2i, width: int, height: int) -> void:
var cells: Array[Vector2i] = []
var source_id = 0
var atlas_coords = Vector2i(1, 1) # Grass tile
for x in range(width):
for y in range(height):
cells.append(chunk_origin + Vector2i(x, y))
# Expert: Bulk setting cells is significantly faster for procedural gen
for cell in cells:
set_cell(cell, source_id, atlas_coords)
# For even better perf with Terrains:
# set_cells_terrain_connect(cells, 0, 0)
# sorting_Z_layering.gd
# Handling Y-sorting and Z-index layering for 2.5D [129]
extends TileMapLayer
# In Godot 4, TileMapLayer nodes can participate in Y-sorting.
func _ready() -> void:
# Enable Y-sorting so children (players) correctly appear
# behind/in-front of trees or walls.
y_sort_enabled = true
# For multi-layered buildings:
# Layer 1 (Ground): Z-Index 0
# Layer 2 (Roof): Z-Index 10 + Y-Sort Disabled (always on top)
# Runtime Z-Index modification for 'entering building' visuals
z_index = -5 if is_underground else 0
extends TileMapLayer
## Expert runtime terrain autotiling with batching and validation.
## Use for destructible terrain or runtime level generation.
@export var terrain_set: int = 0
@export var terrain: int = 0
## Updates a single cell and its neighbors to maintain terrain connectivity.
func set_terrain_cell(coords: Vector2i, type: int = terrain) -> void:
set_cells_terrain_connect([coords], terrain_set, type, true)
## Updates multiple cells in a batch. More efficient than multiple single calls.
func set_terrain_cells(coords_list: Array[Vector2i], type: int = terrain) -> void:
if coords_list.is_empty(): return
set_cells_terrain_connect(coords_list, terrain_set, type, true)
## Clears cells and updates neighbors to fix edges.
func erase_terrain_cells(coords_list: Array[Vector2i]) -> void:
if coords_list.is_empty(): return
for coords in coords_list:
erase_cell(coords)
# Force update neighbors by calling connect on an empty terrain or just refreshing
# In Godot 4, removing then updating neighbors is often done via an update area call
# but set_cells_terrain_connect on neighbors is the most robust way.
var neighbors = []
for cell in coords_list:
for neighbor in get_surrounding_cells(cell):
if neighbor not in neighbors:
neighbors.append(neighbor)
# Refresh neighbors to fix transitions
# We pass -1 or a specific terrain to force refresh
# set_cells_terrain_connect(neighbors, terrain_set, -1, true)
# terrain_path_painter.gd
# Advanced runtime terrain autotiling (Terrains v2) [20, 118]
extends TileMapLayer
# EXPERT NOTE: set_cells_terrain_connect is expensive for large areas.
# Batch tiles and use 'false' for ignore_empty_terrains for predictable
# organic borders.
func draw_road_path(points: Array[Vector2i], terrain_set: int, terrain_id: int) -> void:
# Terrains v2 in Godot 4 automatically handles corner/edge transitions
# based on the bitmask rules in the TileSet resource.
set_cells_terrain_connect(points, terrain_set, terrain_id, false)
# Force an immediate update if this is during a procedural gen step
# update_internals() # Usually not needed but keeps RAM/Editor in sync.
# tile_pattern_stamper.gd
# Using TileMapPatterns for complex, multi-tile stamps
extends TileMapLayer
# Patterns allow you to copy/paste chunks of tiles efficiently.
func stamp_house(origin: Vector2i, pattern: TileMapPattern) -> void:
# Patterns preserve Source IDs, Atlas Coords, and Alternative IDs
set_pattern(origin, pattern)
func copy_area_to_pattern(rect: Rect2i) -> TileMapPattern:
# Captures a region for later use (e.g., custom level editor)
return get_pattern(get_used_cells_by_id().filter(func(c): return rect.has_point(c)))
# skills/tilemap-mastery/scripts/tilemap_chunking.gd
extends Node
## TileMap Chunking Expert Pattern
## Batched terrain updates with chunk-based culling for large procedural worlds.
class_name TileMapChunking
signal chunk_generated(chunk_pos: Vector2i)
@export var tilemap_layer: TileMapLayer
@export var chunk_size := Vector2i(16, 16)
@export var view_distance := 2 # chunks
var _active_chunks := {}
var _chunk_queue := []
func _ready() -> void:
if not tilemap_layer:
push_error("TileMapChunking: tilemap_layer not assigned!")
func update_chunks_around(world_pos: Vector2) -> void:
var center_chunk := world_to_chunk(world_pos)
var required_chunks := _get_required_chunks(center_chunk)
# Unload distant chunks
var to_remove := []
for chunk_pos in _active_chunks:
if chunk_pos not in required_chunks:
to_remove.append(chunk_pos)
for chunk_pos in to_remove:
_unload_chunk(chunk_pos)
# Load new chunks
for chunk_pos in required_chunks:
if chunk_pos not in _active_chunks:
_load_chunk(chunk_pos)
func set_chunk_terrain(chunk_pos: Vector2i, terrain_set: int, terrain: int, cells: Array[Vector2i]) -> void:
if cells.is_empty():
return
# Batch terrain placement
var source_id := 0
tilemap_layer.set_cells_terrain_connect(cells, terrain_set, terrain, false)
_mark_chunk_dirty(chunk_pos)
func set_chunk_cells(chunk_pos: Vector2i, cells: Dictionary) -> void:
# cells = {Vector2i: {source_id, atlas_coords, alternative_tile}}
if cells.is_empty():
return
var positions: Array[Vector2i] = []
var source_ids: Array[int] = []
var atlas_coords: Array[Vector2i] = []
var alternatives: Array[int] = []
for pos in cells:
var data: Dictionary = cells[pos]
positions.append(pos)
source_ids.append(data.get("source_id", 0))
atlas_coords.append(data.get("atlas_coords", Vector2i.ZERO))
alternatives.append(data.get("alternative_tile", 0))
# Batched set_cell
for i in positions.size():
tilemap_layer.set_cell(positions[i], source_ids[i], atlas_coords[i], alternatives[i])
_mark_chunk_dirty(chunk_pos)
func world_to_chunk(world_pos: Vector2) -> Vector2i:
var tile_pos := tilemap_layer.local_to_map(world_pos)
return Vector2i(
floori(float(tile_pos.x) / chunk_size.x),
floori(float(tile_pos.y) / chunk_size.y)
)
func _get_required_chunks(center: Vector2i) -> Array[Vector2i]:
var chunks: Array[Vector2i] = []
for x in range(-view_distance, view_distance + 1):
for y in range(-view_distance, view_distance + 1):
chunks.append(center + Vector2i(x, y))
return chunks
func _load_chunk(chunk_pos: Vector2i) -> void:
_active_chunks[chunk_pos] = true
chunk_generated.emit(chunk_pos)
func _unload_chunk(chunk_pos: Vector2i) -> void:
# Clear tiles in chunk
var start := chunk_pos * chunk_size
var cells_to_erase: Array[Vector2i] = []
for x in chunk_size.x:
for y in chunk_size.y:
cells_to_erase.append(start + Vector2i(x, y))
tilemap_layer.set_cells_terrain_connect(cells_to_erase, 0, -1, false)
_active_chunks.erase(chunk_pos)
func _mark_chunk_dirty(chunk_pos: Vector2i) -> void:
# Force physics/navigation update
tilemap_layer.notify_runtime_tile_data_update()
## EXPERT USAGE:
## var chunking := TileMapChunking.new()
## chunking.tilemap_layer = $TileMapLayer
## chunking.chunk_generated.connect(_on_chunk_generated)
##
## func _process(_delta):
## chunking.update_chunks_around(player.global_position)
# skills/tilemap-mastery/code/tilemap_data_manager.gd
extends Node
## TileMap Mastery Expert Pattern
## Implements Custom DataLayer Logic and Runtime Navigation Baking.
@onready var tilemap_layer: TileMapLayer = $TileMapLayer
# 1. Custom DataLayer Logic
func get_tile_logic(coords: Vector2i) -> Dictionary:
# Professional pattern: Extract metadata directly from the TileSet.
var data = tilemap_layer.get_cell_tile_data(coords)
if not data: return {}
return {
"damage": data.get_custom_data("damage_amount"),
"speed_mult": data.get_custom_data("movement_multiplier"),
"is_slippery": data.get_custom_data("slippery")
}
# 2. Runtime Terrain Manipulation
func paint_path(coords_list: Array[Vector2i], terrain_id: int) -> void:
# Expert logic: Use terrain_connect to automatically handle autotile bitmasks.
tilemap_layer.set_cells_terrain_connect(coords_list, 0, terrain_id)
# 3. Dynamic Navigation Baking
func update_navigation_region() -> void:
# Professional protocol: Force a NavMesh rebake when tiles change.
# Note: In Godot 4, TileSet handles navigation polygons.
# This logic ensures the NavigationServer is updated.
NavigationServer2D.map_set_active(tilemap_layer.get_world_2d().navigation_map, true)
## EXPERT NOTE:
## Use 'Performance Chunking': For 100,000+ tiles, split the
## TileMapLayer into 16x16 chunk scenes. Use 'TileMapLayer.hide()'
## on distant chunks to bypass the quadrant-based drawing cost.
## For 'tilemap-mastery', implement 'TileData Logic Layers':
## Create a 'LogicLayer' Resource that maps Tile IDs to Game Effects
## (e.g. ID 5 = LavaArea3D spawner).
## NEVER check Tile IDs directly in gameplay code; always use
## 'get_custom_data()' to decouple visual assets from technical logic.
## Use 'set_cells_terrain_connect' instead of manual bitmasking
## to allow for dynamic, runtime level destruction/creation.
# tilemap_layer_v43_upgrade.gd
# Handling multiple TileMapLayer nodes (Godot 4.3+ standard)
extends Node2D
# In 4.3+, the single TileMap node with 'Layers' is deprecated.
# Use multiple TileMapLayer children for better performance and flexibility.
func get_combined_used_rect() -> Rect2:
var total_rect = Rect2()
for child in get_children():
if child is TileMapLayer:
var layer_rect = child.get_used_rect()
# Convert map to world
var world_rect = Rect2(child.map_to_local(layer_rect.position), layer_rect.size * 16) # Assume 16px
total_rect = total_rect.merge(world_rect)
return total_rect