#Unity Physics - Collision Filter GroupIndex issue

1 messages · Page 1 of 1 (latest)

rapid zodiac
#

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

  1. If both GroupIndexes are THE SAME and POSITIVE collision will always happen
  2. If both GroupIndex are THE SAME and NEGATIVE collision will never happen
  3. If both GroupIndex are 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.

#

Furthermore the issue can be replicated the other way.
If I set the CollisionFilter to Default and then set both group indexes to negative numbers, even different ones, the collision will never occur.
Interestingly in this case setting one of them to negative and keeping other one at 0 will work properly and the collision will occur.

#

And before anyone asks:

  • Debug.Log does confirm that they values I set as GroupIndex are the ones I described here.
  • Yes the system does run on both entities, I can see it using the editor tools.
#

It would be nice if someone tried to replicate the issue so I know if it's something I'm doing wrong / misunderstanding or if it's maybe a bug!

thin agate
#

OH

#

do your entities have the same collider?

#

they're blobs they share memory

#

2 entities share the same collider if they're the same during baking

#

updating the filter on 1 will update the filter on the other as well

#

so you're just setting both colliders to 1, then both colliders to 2

#

so the group mask is always the same on your colliders

#

(if you use my core library you can inspect colliders/groupmask in the inspector to confirm this)

rapid zodiac
#

That's a good theory, but how can I check it? :v

thin agate
#

create 2 entities with different collider types

#

1 sphere, 1 cube or something

rapid zodiac
#

Alright gimme a sec

#

Btw where can I get ur lib from and how to install it, might be useful in the future :p

thin agate
#

is what my library will show you

#

upm is a little out of date vs the branch i'm developing on

#

i believe it should be up to date with latest entities

#

is the file that provides the custom inspector for physics

#

if the hash are equal between different entities

#

it's the same memory

rapid zodiac
#

Bro

#

I love you

#

That was it

#

I changed one of the colliders to different type and everything works nicely

thin agate
#

so yeah this is the issue with filters atm

#

you change 1, you change all

rapid zodiac
#

How do I avoid it?

thin agate
#

there are discussions from unity for removing the collision filter out of the blob

#

so it is no longer shared / can be easily edited

#

if you use the old, physicsshape authoring

#

there is a button on there to make it unique

#

it will be a lot of wasted memory though

rapid zodiac
#

Sooo, there is no good way to do it?

#

Also I don't think PhysicsShape is a thing in this new version

#

At least I can't find it

thin agate
#

you have to import the sample

#

they removed it from the default package and into the samples

#

so promote using in built colliders

#

but inbuilt colliders miss a lot of functionality over the old authoring scripts......

rapid zodiac
#

Library\PackageCache\com.unity.logging@1.0.8\Runtime\Sinks\UnityEditorConsoleSink.cs(9,30): error CS0234: The type or namespace name 'UTF8StringView' does not exist in the namespace 'UnityEngine' (are you missing an assembly reference?)

#

My Unity doesn't seem to like ur package

thin agate
#

that bug is fixed in logging 1.0.11

#

(its a bug in logging package not my package)

#

the latest version of my package from the branch should have a dependency on it

#

but you'll need to update manually if you're using upm etc

#

i forgot that was a thing

#

i should probably push a new upm version

rapid zodiac
#

Right got it

thin agate
#

might try do that this arvo, thanks for heads up

rapid zodiac
#

Since I had logging installed as dependency unity decided not to tell me there is an update for it and show a green check mark instead lol. I had to click on it and go into versions tab

#

So I was sitting on 1.0.8

#

Yep everything works now

thin agate
#

👍

rapid zodiac
#

Thanks again for everything, I was banging my head on it for the past 2 or 3 hours lol

thin agate
#

just pushed 0.15.3 to github/openupm with this fixed

#

(and a bunch of other things)

#

thanks for the push ^^

forest egret
#

Thanks @thin agate for the great answers here, and sorry about the confusion @rapid zodiac .
We are currently looking into improving this situation.
For reference, here is a discussion about these challenges in the Unity Forum which we have been tracking.
https://forum.unity.com/threads/collisionfilter-as-a-separate-icomponentdata.1412157/