Search Unity

ITriggerJob causes a crash after scene reloads

Discussion in 'Physics for ECS' started by Conspiracy, Jan 12, 2020.

  1. Conspiracy

    Conspiracy

    Joined:
    Oct 22, 2016
    Posts:
    40
    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.
    Code (CSharp):
    1. public class triggerWithPlayerSystem : JobComponentSystem
    2. {
    3.     [BurstCompile]
    4.     public struct PlayerOnTriggerJob : ITriggerEventsJob
    5.     {
    6.         [ReadOnly]
    7.         public ComponentDataFromEntity<playerData> playerEntity;
    8.         public ComponentDataFromEntity<triggerComponent> triggerEntity;
    9.         public void Execute(TriggerEvent triggerEvent)
    10.         {
    11.             if (playerEntity.HasComponent(triggerEvent.Entities.EntityA))
    12.             {
    13.                 if (triggerEntity.HasComponent(triggerEvent.Entities.EntityB))
    14.                 {
    15.                     triggerComponent trigger = triggerEntity[triggerEvent.Entities.EntityB];
    16.                     trigger.active = true;
    17.                     triggerEntity[triggerEvent.Entities.EntityB] = trigger;
    18.                 }
    19.             }
    20.             if (playerEntity.HasComponent(triggerEvent.Entities.EntityB))
    21.             {
    22.                 if (triggerEntity.HasComponent(triggerEvent.Entities.EntityA))
    23.                 {
    24.                     triggerComponent trigger = triggerEntity[triggerEvent.Entities.EntityB];
    25.                     trigger.active = true;
    26.                     triggerEntity[triggerEvent.Entities.EntityB] = trigger;
    27.                 }
    28.             }
    29.         }
    30.     }
    31.     private BuildPhysicsWorld buildPhysicsWorld;
    32.     private StepPhysicsWorld stepPhysicsWorld;
    33.     protected override void OnCreate()
    34.     {
    35.         if(buildPhysicsWorld == null)
    36.             buildPhysicsWorld = World.GetOrCreateSystem<BuildPhysicsWorld>();
    37.         if (stepPhysicsWorld == null)
    38.             stepPhysicsWorld = World.GetOrCreateSystem<StepPhysicsWorld>();
    39.     }
    40.     protected override JobHandle OnUpdate(JobHandle inputDeps)
    41.     {
    42.         PlayerOnTriggerJob job = new PlayerOnTriggerJob
    43.         {
    44.             playerEntity = GetComponentDataFromEntity<playerData>(isReadOnly: true),
    45.             triggerEntity = GetComponentDataFromEntity<triggerComponent>(),
    46.         };
    47.         return job.Schedule(stepPhysicsWorld.Simulation, ref buildPhysicsWorld.PhysicsWorld, inputDeps);
    48.     }
    49. }
    any reason why?
     
  2. florianhanke

    florianhanke

    Joined:
    Jun 8, 2018
    Posts:
    426
    Shouldn‘t it be EntityA in the lower code part?
     
    Conspiracy likes this.
  3. Conspiracy

    Conspiracy

    Joined:
    Oct 22, 2016
    Posts:
    40
    Ah damn. thank you but i dont think that's the cause of it. Ill try to fix it still see if it helps
     
    florianhanke likes this.
  4. Conspiracy

    Conspiracy

    Joined:
    Oct 22, 2016
    Posts:
    40
    Actually it is whats causing it. Thanks again
     
    florianhanke likes this.
  5. florianhanke

    florianhanke

    Joined:
    Jun 8, 2018
    Posts:
    426
    Glad to hear it!
     
    Conspiracy likes this.