ITriggerJob Sample

I am so lost with this so any help much appreciated.

   struct ListTriggerEventEntitiesJob : ITriggerEventsJob
    {
        [ReadOnly] public ComponentDataFromEntity<PhysicsVelocity> PhysicsVelocityGroup;
        [ReadOnly] public ComponentDataFromEntity<TriggerVolume> VolumeGroup;

        [NativeFixedLength(1)] public NativeArray<int> pCounter;
        public NativeArray<TriggerEntities> TriggerEntities;

        public void Execute(TriggerEvent triggerEvent)
        {
            Entity entityA = triggerEvent.Entities.EntityA;
            Entity entityB = triggerEvent.Entities.EntityB;

            bool isBodyATrigger = VolumeGroup.Exists(entityA);
            bool isBodyBTrigger = VolumeGroup.Exists(entityB);


            //Ignoring Triggers overlapping other Triggers
            if (isBodyATrigger && isBodyBTrigger)
                return;

            bool isBodyADynamic = PhysicsVelocityGroup.Exists(entityA);
            bool isBodyBDynamic = PhysicsVelocityGroup.Exists(entityB);

            // Ignoring overlapping static bodies
            if ((isBodyATrigger && !isBodyBDynamic) ||
                (isBodyBTrigger && !isBodyADynamic))
                return;

            // Increment the output counter in a thread safe way.
            var count = ++pCounter[0] - 1;

            TriggerEntities[count] = new TriggerEntities()
            {
                VolumeEntity = isBodyATrigger ? entityA : entityB,
                OverlappingEntity = isBodyATrigger ? entityB : entityA,
            };
        }
    }

The main thing I am stuck on currently is

            //Ignoring Triggers overlapping other Triggers
            if (isBodyATrigger && isBodyBTrigger)
                return;

Why is this ignored?
I thought ITriggerJob is triggered when two triggers collide so why ignore this when it happens???

1 Like

ITriggerEvent is raised/trigerred whenever a collider marked as trigger collides with another collider wahterver the type trigger or not.

In some cases it might make sense to igrone two trigger collider interacting with each other.

For exemple you make a FPS with "real" projectile (not simple raycast but real physics body and a trigger collider) the projectile travel through the world and cross pass with another trigger colider which purpose is to open a door.
Do you want the projectile to trigger the opening door animation?
I think not.

2 Likes