ICollisionEventsJob Not Firing on entities with a dynamically created physics collider

Im dynamically spawning a bunch of entities which I am dynamically resizing.
In order to affect the colliders scale i am making a new Physics collider to represent the new size using:

BlobAssetReference<Unity.Physics.Collider> collider = Unity.Physics.SphereCollider.Create(new SphereGeometry
{
        Center = float3.zero,
        Radius = radius
});
               
                commandBuffer.SetComponent(entityInQueryIndex, instantiatedEntity, new PhysicsCollider { Value = collider});

However when i do this i no longer have my CollisionEventsJob fire. (They fire properly if i dont set the PhysicsCollider component)

I assume this is because the collision response is not set to raise collision events on the dynamically instantiated PhysicsCollider.

Is there a way to set the collision response dynamically? Or could this be caused by some other data that i need to set on the PhysicsCollider?

Thanks.

Of course I manage to resolve my issue after I post about it…
I found that I can assign a physicsMaterial in the Create() method. So i made a new one and set its collisionResponsePolicy and now my events are firing.
Fixed code:

Unity.Physics.Material physMat = Unity.Physics.Material.Default;
                physMat.CollisionResponse = CollisionResponsePolicy.CollideRaiseCollisionEvents;
                BlobAssetReference<Unity.Physics.Collider> collider = Unity.Physics.SphereCollider.Create(new SphereGeometry
                {
                    Center = float3.zero,
                    Radius = radius
                }, CollisionFilter.Default, physMat);
               
                commandBuffer.SetComponent(entityInQueryIndex, instantiatedEntity, new PhysicsCollider { Value = collider});
2 Likes