ITriggerJob causes a crash after scene reloads

so I have this triggerJob in my game. When I start the game the Job works fine but after the scene resets, that job causes my game to just stop working.

public class triggerWithPlayerSystem : JobComponentSystem
{
    [BurstCompile]
    public struct PlayerOnTriggerJob : ITriggerEventsJob
    {
        [ReadOnly]
        public ComponentDataFromEntity<playerData> playerEntity;
        public ComponentDataFromEntity<triggerComponent> triggerEntity;
        public void Execute(TriggerEvent triggerEvent)
        {
            if (playerEntity.HasComponent(triggerEvent.Entities.EntityA))
            {
                if (triggerEntity.HasComponent(triggerEvent.Entities.EntityB))
                {
                    triggerComponent trigger = triggerEntity[triggerEvent.Entities.EntityB];
                    trigger.active = true;
                    triggerEntity[triggerEvent.Entities.EntityB] = trigger;
                }
            }
            if (playerEntity.HasComponent(triggerEvent.Entities.EntityB))
            {
                if (triggerEntity.HasComponent(triggerEvent.Entities.EntityA))
                {
                    triggerComponent trigger = triggerEntity[triggerEvent.Entities.EntityB];
                    trigger.active = true;
                    triggerEntity[triggerEvent.Entities.EntityB] = trigger;
                }
            }
        }
    }
    private BuildPhysicsWorld buildPhysicsWorld;
    private StepPhysicsWorld stepPhysicsWorld;
    protected override void OnCreate()
    {
        if(buildPhysicsWorld == null)
            buildPhysicsWorld = World.GetOrCreateSystem<BuildPhysicsWorld>();
        if (stepPhysicsWorld == null)
            stepPhysicsWorld = World.GetOrCreateSystem<StepPhysicsWorld>();
    }
    protected override JobHandle OnUpdate(JobHandle inputDeps)
    {
        PlayerOnTriggerJob job = new PlayerOnTriggerJob
        {
            playerEntity = GetComponentDataFromEntity<playerData>(isReadOnly: true),
            triggerEntity = GetComponentDataFromEntity<triggerComponent>(),
        };
        return job.Schedule(stepPhysicsWorld.Simulation, ref buildPhysicsWorld.PhysicsWorld, inputDeps);
    }
}

any reason why?

Shouldn‘t it be EntityA in the lower code part?

1 Like

Ah damn. thank you but i dont think that’s the cause of it. Ill try to fix it still see if it helps

1 Like

Actually it is whats causing it. Thanks again

1 Like

Glad to hear it!

1 Like