0 votes

The docs for Area2D state

void set_collision_layer_bit( int bit, bool value ) Set/clear
individual bits on the layer mask. This makes getting an area in/out
of only one layer easier.

void set_collision_mask_bit( int bit, bool value ) Set/clear
individual bits on the collision mask. This makes selecting the areas
scanned easier.

What is the bool for?

This thread makes it look like the bool is for using decimal (instead of binary) numbers.

What is the max decimal number we can use: 32, 20, or something else?

Edit: I ask about the max index because the docs state

int collisionlayer - The area’s physics layer(s). Collidable objects
can exist in any of 32 different layers. A contact is detected if
object A is in any of the layers that object B scans, or object B is
in any layers that object A scans. See also collision
mask.

asked May 15 in Engine by jarlowrey (468 points)
edited May 15 by jarlowrey

1 Answer

+1 vote
Best answer

Bool is a desired value of a bit. Int is an index of that bit.

set_collision_layer_bit( 4, false )

will set 5th bit to false.
That's how it works for me in Godot 3.0.2.

According to Inspector there are 20 bits for layer and 20 for mask so maximum index would be 19.

answered May 15 by hilfazer (1,434 points)
selected May 15 by jarlowrey

Ah ok. Lol of course. I guess I'll stick with 20 but the docs are confusing, because they claim 32.

I did this

set_collision_layer_bit(306, true)
get_collision_layer_bit(306)

and it appeared to work. But it's likely NOT SAFE to do.

20 is plenty. If you don't need more than that then it does not matter if there are more than 20 bits :)

Wow that's strange 306 worked. I assume it was represented as a 32 bit unsigned integer under the hood, that's why 32 seems like a reasonable unit. Maybe the 306 just overflowed and wrapped around.

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 How to use this Q&A? before posting your first questions.