Check out our latest project ✨ OpenChapter.io: free ebooks the way its meant to be 📖

LayerStringHelper

An asset by [email protected]
The page banner background of a mountain and forest
LayerStringHelper hero image

Quick Information

0 ratings
LayerStringHelper icon image
LayerStringHelper

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.

Supported Engine Version
4.0
Version String
1.0
License Version
MIT
Support Level
community
Modified Date
4 hours ago
Git URL
Issue URL

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_layer and collision_mask by 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

  1. Copy script.gd into your Godot project.
  2. Add it as a child of your physics node, or attach directly.
  3. Set layer_names to match your project's Physics Layer names exactly (Project > Project Settings > Layer Names > 2D Physics).
  4. Set collision_layer_names and collision_mask_names to the layers you want active.
  5. 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

0 ratings

Your Rating

Headline must be at least 3 characters but not more than 50
Review must be at least 5 characters but not more than 500
Please sign in to add a review

Quick Information

0 ratings
LayerStringHelper icon image
LayerStringHelper

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.

Supported Engine Version
4.0
Version String
1.0
License Version
MIT
Support Level
community
Modified Date
4 hours ago
Git URL
Issue URL

Open Source

Released under the AGPLv3 license

Plug and Play

Browse assets directly from Godot

Community Driven

Created by developers for developers