#Do ICollisionEventsJob run when using unity native Rigidbody and colliders?

1 messages · Page 1 of 1 (latest)

lethal marsh
#

I've been referencing some of the collision examples in the github repo and they all are still using components from the custom physics authoring. From what I can tell, Unity seems to be adding these behaviours to the base components like Rigidbody

#

I am trying to build a simple collision system:

[UpdateInGroup(typeof(PhysicsSystemGroup))]
[UpdateAfter(typeof(PhysicsSimulationGroup))]
public partial struct DamageCollisionSystem : ISystem
{
    [BurstCompile]
    public void OnCreate(ref SystemState state)
    {
        state.RequireForUpdate<SimulationSingleton>();
    }

    [BurstCompile]
    public void OnUpdate(ref SystemState state)
    {
        state.Dependency = new DamageCollisionJob
        {
            DamagerData = SystemAPI.GetComponentLookup<DamagerData>(),
            DamageableData = SystemAPI.GetComponentLookup<DamageableData>(),
        }.Schedule(SystemAPI.GetSingleton<SimulationSingleton>(), state.Dependency);
    }

    [BurstCompile]
    struct DamageCollisionJob : ICollisionEventsJob
    {
        [ReadOnly] public ComponentLookup<DamagerData> DamagerData;
        public ComponentLookup<DamageableData> DamageableData;
        public void Execute(CollisionEvent collisionEvent)
        {
            Entity entityA = collisionEvent.EntityA;
            Entity entityB = collisionEvent.EntityB;

            bool isEntityADamageDealer = DamagerData.HasComponent(entityA);
            bool isEntityBDamageDealer = DamagerData.HasComponent(entityB);

            bool isEntityADamageable = DamageableData.HasComponent(entityA);
            bool isEntityBDamageable = DamageableData.HasComponent(entityB);

            if (isEntityADamageDealer && isEntityBDamageable)
            {
                var damageDealer = DamagerData[entityA];
                var damageable = DamageableData[entityB];

                DealDamage(damageable, damageDealer);
            }

            if (isEntityADamageable && isEntityBDamageDealer)
            {
                var damageDealer = DamagerData[entityB];
                var damageable = DamageableData[entityA];

                DealDamage(damageable, damageDealer);
            }
        }
    }
}
#

though the DamageCollisionJob Execute function never executes, I have tried all permutations of options on my Collider and Rigidbody components

#

It makes use of Physics Shape > Collision Response > Collide Raises Collision Events

#

Is there support for this behaviour with simple native Rigidbody and Collider components, or do I need to make use of the additional authoring components in the extra library for this right now?

#

Right now I have a simple sphere and cube colliding on the Default layer, but no ICollisionEventJob execute

#

Do ICollisionEventsJob run when using unity native Rigidbody and colliders?