Godot Version
4.4
Greetings!

I’ve been doing some research about collisions in Godot 3D, I found that collisions layers and masks could be named by the “Project Settings” and set in the respective property for CollisionObject3D nodes.
Besides I have no doubt how to set them and how to detect them by the ‘on_body_entered’ method, I couldn’t get the identifier name of the body that has entered in the collision space.
When I try to get collision_layer property I get the number of corresponding bit, netherless I need the name from the corresponding layer so I try to get it from “ProjectSettings” as next:
Question is: Which is the best approach to get the collision layers names? 
the body.collision_layer
is not the bit, it’s all of the bits, 32 of them.
Getting the layer names from the project settings is the best way to do it, probably the only way; but objects can have more than one layer/mask bit set, so I’m not sure why you’d want to do this.
If you want to check an object has the third bit set you can use get_collision_layer_value
/get_collision_mask_value
or bitwise operators.
if body.get_collision_layer_value(3):
print("is obstacle")
if (body.collision_layer & 0b100) != 0:
print("is obstacle")
1 Like
Ok, got it.
So saying is better to just compare if you have the specific layer, instead of retreiving the name? But then you should know all the values of layers 
I am looking for the specific layer to execute different behaviors, depending on the type of body that enters.
Sadly you do need to know the layer values, bitmaps do not have a good way to translate to and from strings. It would be best to use one of the methods I posted
1 Like