https://docs.unity3d.com/Packages/com.unity.physics@1.0/manual/collision-queries.html#filtering
For my project I need to run physics simulation for entities divided into groups. Entities in one group can only interact with other entities in the same group. Obvious solution would be collision layers using bit masks but these are limited to 32 layers and I might need more than that. Alternative option is usage of GroupIndex but it's been giving me trouble.
I created a test scenario to figure out how these work. My scene only consists of 2 entities, both with physics and one falls on top of another.
I created this system to test the groupIndex thing and there seems to be a either a bug or my mistake that causes incorrect behaviour.
As explained in the link at the top:
GroupIndex overrides bit masks as follows
- If both
GroupIndexesare THE SAME and POSITIVE collision will always happen - If both
GroupIndexare THE SAME and NEGATIVE collision will never happen - If both
GroupIndexare DIFFERENT OR BOTH EQUAL TO 0 then collision will be processed normally according to the bit masks
The Issue:
In my test system shown in the picture I'm modifying the CollisionFilter of both of my entities. CollisionFilter is set as CollisionFilter.Zero causing no collisions at all according to bit masks. Then I'm overriding the GroupIndex so that one collider has it set to 1 and other collider to 2.
According to documentation, since these are different the collision should be processed according to bit masks, so no collision should happen. However when tested both entities collide. Same happens if I set both GroupIndexes to any two positive values, or even if I set one of the to positive value and keep other one at 0. If I understand it correctly this shouldn't happen and I'm really confused.