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
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 projectAdd 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.
LayerStringHelper — Lite
Stop fighting your engine. Ship faster.
The Problem
Physics layer collision masks are set as bitmask integers. Bit 1 = layer 1, bit 2 = 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.
The Solution
Add script.gd as a child of any physics node. Enter your project's layer names in the Inspector once. Then specify which layers should be active by name — the script computes the bitmask and writes it automatically.
No plugins. No autoloads. One file.
What's in the Lite Version
- Configure
collision_layerandcollision_maskby layer name array via Inspector names_to_bitmask(["Enemy", "World"])public method for code-side use- Auto-applies on
_ready()(configurable) - Works as a child node or directly attached to the physics node
- Debug output prints computed bitmasks in 20-bit binary for easy verification
- Supports all physics nodes: CharacterBody2D, RayCast2D, Area2D, etc.
What's in the Full Version
The full version adds bitmask_to_names(int): given a raw bitmask integer from a live physics node, it returns the array of active layer names. This is the function you need when reading collision state at runtime — for debugging live physics interactions, logging hit results, and building systems that serialize collision configuration by name rather than by magic number.
Full version on itch.io: https://nullstateassets.itch.io
Quick Start
- Copy
script.gdinto your Godot project. - Add it as a child of your physics node, or attach directly.
- Set
layer_namesto match your project's Physics Layer names exactly (Project > Project Settings > Layer Names > 2D Physics). - Set
collision_layer_namesandcollision_mask_namesto the layers you want active. - 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.
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.
Reviews
Quick Information
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 projectAdd 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.