+6 votes

Playing around with the new layer naming. It's nice for the UI, but in GDScript is there any way to set a mask using one of those assigned names?

in Engine by (5,264 points)

Yeah, I'm also looking for a way to get layer name by it's ID

I haven't been able to find any clean or built in way to access them. :/

If you need something, my current solution is use a dictionary to build a table out of the settings that maps the associated power of two to the layer name.

Though may want to reverse the key and value, depending on how you want to use it.

var mask_bit_to_name = {}

for i in range(1, 21):

    var layer_name = ProjectSettings.get_setting(
        str("layer_names/2d_physics/layer_", i))

    if(not layer_name): layer_name = str("Layer ", i)

    mask_bit_to_name[pow(2, i-1)] = layer_name

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.