Install Asset
Install via Godot
To maintain one source of truth, Godot Asset Library is just a mirror of the old asset library so you can download directly on Godot via the integrated asset library browser
Quick Information
Name-based collision layer management for TileMap in Godot 4.x.TileMap.set_layer_enabled() takes a layer index — a raw integer. Your layers have names. Every time you restructure your TileMap, those indices shift silently and your collision code breaks with no error messages. You are manually maintaining a number-to-name mapping in your head.This script builds a name-to-index cache at startup and exposes a clean string-based API. Write set_collision_enabled_by_name("Ground", true) instead of set_layer_enabled(2, true). Your code survives TileMap restructuring because it never references indices directly.Features:- Name-to-index cache built automatically on ready- set_collision_enabled_by_name() for single layer control- refresh_layer_cache() to rebuild after runtime structural changes- Inspector-configured initial collision state on scene load- Duplicate layer name detection with warnings- Debug layer map printing via Inspector toggle- Zero dependencies — works in a blank projectAttach TileMapCollisionManager.gd to your TileMap node. It replaces TileMap as the base class. Set initial_enabled_layers in the Inspector. Done.Godot 4.x only. GDScript 2.0.Extended version with batch methods, global toggles, and state snapshot serialization available at nullstateassets.itch.io.
TileMapCollisionManager — Lite
Stop fighting your engine. Ship faster.
The Problem
TileMap.set_layer_enabled() takes a layer index — a raw integer. Your layers have names. Every time you refactor your TileMap structure, those indices silently shift and your collision code breaks in ways that produce no error messages. You are manually maintaining a number↔name mapping in your head.
The Solution
Drop script.gd onto your TileMap node. It builds a name→index cache at startup and exposes a clean string-based API. Call set_collision_enabled_by_name("Ground", true) instead of set_layer_enabled(2, true). Your code survives TileMap restructuring.
No plugins. No autoloads. One file.
What's in the Lite Version
- Automatic name→index cache built on
_ready() set_collision_enabled_by_name(name, bool)— single layer controlrefresh_layer_cache()— rebuild cache after runtime structural changes- Inspector-configured initial collision state on scene load
- Duplicate layer name detection and warnings
- Debug layer map printing
What's in the Full Version
The full version adds batch methods (enable_layers_by_name, disable_layers_by_name), global toggles (disable_all_collision, enable_all_collision), and state serialization (get_collision_state_snapshot, restore_collision_state_snapshot) — essential for save/load systems and cutscene state management.
Full version on itch.io: https://nullstateassets.itch.io
Quick Start
- Copy
script.gdinto your Godot project. - Attach it to your TileMap node (replaces it — TileMap is the base class).
- Add your layer names to
initial_enabled_layersin the Inspector. - Hit Play.
Compatibility
| Engine | Language | Tested On |
|---|---|---|
| Godot 4.x | GDScript | 4.2, 4.3 |
License
MIT License. Free for personal and commercial use. Attribution appreciated but not required.
Name-based collision layer management for TileMap in Godot 4.x.
TileMap.set_layer_enabled() takes a layer index — a raw integer. Your layers have names. Every time you restructure your TileMap, those indices shift silently and your collision code breaks with no error messages. You are manually maintaining a number-to-name mapping in your head.
This script builds a name-to-index cache at startup and exposes a clean string-based API. Write set_collision_enabled_by_name("Ground", true) instead of set_layer_enabled(2, true). Your code survives TileMap restructuring because it never references indices directly.
Features:
- Name-to-index cache built automatically on ready
- set_collision_enabled_by_name() for single layer control
- refresh_layer_cache() to rebuild after runtime structural changes
- Inspector-configured initial collision state on scene load
- Duplicate layer name detection with warnings
- Debug layer map printing via Inspector toggle
- Zero dependencies — works in a blank project
Attach TileMapCollisionManager.gd to your TileMap node. It replaces TileMap as the base class. Set initial_enabled_layers in the Inspector. Done.
Godot 4.x only. GDScript 2.0.
Extended version with batch methods, global toggles, and state snapshot serialization available at nullstateassets.itch.io.
Reviews
Quick Information
Name-based collision layer management for TileMap in Godot 4.x.TileMap.set_layer_enabled() takes a layer index — a raw integer. Your layers have names. Every time you restructure your TileMap, those indices shift silently and your collision code breaks with no error messages. You are manually maintaining a number-to-name mapping in your head.This script builds a name-to-index cache at startup and exposes a clean string-based API. Write set_collision_enabled_by_name("Ground", true) instead of set_layer_enabled(2, true). Your code survives TileMap restructuring because it never references indices directly.Features:- Name-to-index cache built automatically on ready- set_collision_enabled_by_name() for single layer control- refresh_layer_cache() to rebuild after runtime structural changes- Inspector-configured initial collision state on scene load- Duplicate layer name detection with warnings- Debug layer map printing via Inspector toggle- Zero dependencies — works in a blank projectAttach TileMapCollisionManager.gd to your TileMap node. It replaces TileMap as the base class. Set initial_enabled_layers in the Inspector. Done.Godot 4.x only. GDScript 2.0.Extended version with batch methods, global toggles, and state snapshot serialization available at nullstateassets.itch.io.