#Do ICollisionEventsJob run when using unity native Rigidbody and colliders?
1 messages · Page 1 of 1 (latest)
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
The example I am referencing is https://github.com/Unity-Technologies/EntityComponentSystemSamples/blob/master/PhysicsSamples/Assets/6. Events/Scripts/CollisionEventImpulseSystem.cs
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?