LayerStringHelper's icon

LayerStringHelper 1.0 Scripts 4.0 Community

Submitted by user [email protected]; MIT; 2026-03-02

Set physics layer collision masks by name instead of bitmask arithmetic in Godot 4.x.

Physics layer collision masks are set as bitmask integers. Bit 1 is layer 1, bit 2 is layer 2, and so on. To enable layers 1, 3, and 5 you write 1 + 4 + 16 = 21. You recalculate this by hand every time your layer assignments change. One wrong number and your raycasts silently hit the wrong things with no warning.

This script reads a list of layer names from the Inspector and translates them into the correct bitmask at runtime. Set collision_layer_names to ["Player", "Projectile"] and collision_mask_names to ["Enemy", "World"] — the script does the math.

Features:
- Configure collision_layer and collision_mask by layer name array via Inspector
- names_to_bitmask() public method for code-side use without a target node
- Applies automatically on ready (configurable)
- Works as a child node or attached directly to the physics node
- Auto-detects parent physics node — no explicit assignment required
- Debug output prints computed masks as 20-bit binary strings for visual verification
- Compatible with CharacterBody2D, RayCast2D, Area2D, and any physics node
- Zero dependencies — works in a blank project

Add LayerStringHelper.gd as a child of your physics node. Set layer_names to match your project settings. Assign your desired layers by name. Done.

Godot 4.x only. GDScript 2.0.

Extended version with bitmask_to_names() inverse lookup for reading and debugging live collision state available at nullstateassets.itch.io.


View files Download Submit an issue Recent Edits