Filter changed in PhysicsCollider component for one Entity affects all of them

Hello,

I am currently experimenting with the ECS character controller (1.2.4).
I am developing a zombie survivor type of game.
I have however hit a little snag:
When my hero kills a zombie, I want to play the death animation before I destroy the entity, however I don’t want my hero to target it any longer:
I use a overlap sphere to find enemies in proximity, the cast a ray for the bullet interaction.
For both of these things I use a Collision filter:
BelongsTo: player
CollidesWith: Zombie

I define those on the physics shape assigned to my prefab.

So, the way I was going about this was to add the PhysicsCollider component to my query when in the DeathHandling system,

Then I Set a new CollisionFilter to the collider:

unsafe {
        if (physicsCollider.ColliderPtr != null) {
          CapsuleCollider* collider = (CapsuleCollider*) physicsCollider.ColliderPtr;
          
          collider->SetCollisionFilter(new CollisionFilter {
            BelongsTo = (uint)PhysicsLayers.Dead,
            CollidesWith = ~0u,
          });
        }
      }

However this changes to every unit present in my scene, not only the one I called it on.
I am sure it is called only on that single zombie because I was logging the entity index to verify.

I am not sure if this is a bug, or it is the way it is supposed to be.
Being the collider a pointer, could it be that they all point to the same one? if so, why?

Can anybody suggest a solution or an alternative method to achieve my main goal:
still have the character on the scene but prevent any interaction with the player?

Thanks
Kind Regards

Joe

So, I found a toggle in the Physics shape to force unique, which solved my first problem.
However, I have another issue:
If one of the children of the entity I am changing collision for have a collider (physics shape) I get the following error:
ArgumentException: FixedString128Bytes: Truncation while copying “CollisionFilter of a compound collider is not a union of its children. You must call CompoundCollider.RefreshCollisionFilter() to update the root filter after changing child filters.”
Unity.Collections.FixedString128Bytes.CheckCopyError (Unity.Collections.CopyError error, System.String source) (at ./Library/PackageCache/com.unity.collections/Unity.Collections/FixedString.gen.cs:4646)

Any ideas?

As you already found out, this is normal behavior since identical baked colliders are shared by default in Unity Physics to reduce the memory footprint.
This is discussed in the documentation here.

This section also shows how to make colliders unique if you need to modify them without affecting others.
There are various ways to achieve this, with the “force unique” option in the custom authoring components being one of them.

As stated in the warning message, you need to call CompoundCollider.RefreshCollisionFilter after changing the collision filter of a child collider in a CompoundCollider. That should fix this issue.