Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Bug ITriggerEventsJob Issue

Discussion in 'Entity Component System' started by piginaust, Dec 15, 2022.

  1. piginaust

    piginaust

    Joined:
    May 23, 2022
    Posts:
    14
    I have set up ITriggerJob as follows:

    Code (CSharp):
    1.  
    2. [UpdateInGroup(typeof(FixedStepSimulationSystemGroup))]
    3. [BurstCompile]
    4. public partial struct BulletCollisionSystem : ISystem
    5. {
    6.     ComponentLookup<BulletLifeTimeSpeedData> bulletTag;
    7.     ComponentLookup<EnemyTag> enemyTag;
    8.  
    9.     [BurstCompile]
    10.     public void OnCreate(ref SystemState state)
    11.     {
    12.         state.RequireForUpdate<BulletLifeTimeSpeedData>();
    13.  
    14.         bulletTag = state.GetComponentLookup<BulletLifeTimeSpeedData>(true);
    15.         enemyTag = state.GetComponentLookup<EnemyTag>(true);
    16.     }
    17.     [BurstCompile]
    18.     public void OnDestroy(ref SystemState state)
    19.     {}
    20.     [BurstCompile]
    21.     public void OnUpdate(ref SystemState state)
    22.     {
    23.         var ecbSingleton = SystemAPI.GetSingleton<BeginSimulationEntityCommandBufferSystem.Singleton>();
    24.         var ecb = ecbSingleton.CreateCommandBuffer(state.WorldUnmanaged);
    25.         var simulationSingleton = SystemAPI.GetSingleton<SimulationSingleton>();
    26.  
    27.         bulletTag.Update(ref state);
    28.         enemyTag.Update(ref state);
    29.  
    30.         JobHandle trigger = new TriggerJob
    31.         {
    32.             bulletTag = bulletTag,
    33.             enemyTag = enemyTag,
    34.             commandBuffer = ecb,
    35.         }.Schedule(simulationSingleton, state.Dependency);
    36.  
    37.         trigger.Complete();
    38.     }
    39.  
    40.     [BurstCompile]
    41.     private struct TriggerJob : ITriggerEventsJob
    42.     {
    43.         [ReadOnly] public ComponentLookup<BulletLifeTimeSpeedData> bulletTag;
    44.         [ReadOnly] public ComponentLookup<EnemyTag> enemyTag;
    45.         public EntityCommandBuffer commandBuffer;
    46.  
    47.     [BurstCompile]
    48.         public void Execute(TriggerEvent triggerEvent)
    49.         {
    50.             Entity entityA = triggerEvent.EntityA;
    51.             Entity entityB = triggerEvent.EntityB;
    52.  
    53.             Entity bulletEntity = Entity.Null;
    54.             Entity EnemyEntity = Entity.Null;
    55.  
    56.             if(bulletTag.HasComponent(entityA)) bulletEntity = entityA;
    57.             if(bulletTag.HasComponent(entityB)) bulletEntity = entityB;
    58.  
    59.             if(enemyTag.HasComponent(entityA)) EnemyEntity = entityA;
    60.             if(enemyTag.HasComponent(entityB)) EnemyEntity = entityB;
    61.  
    62.             if(bulletEntity != Entity.Null && EnemyEntity != Entity.Null)
    63.             {            
    64.                 commandBuffer.SetComponentEnabled<BeingAttackedTag>(EnemyEntity, true);
    65.                 commandBuffer.DestroyEntity(bulletEntity);
    66.             }
    67.         }
    68.     }
    69. }
    It works fine, BUT....

    If I enter playmode, and then click Entities Hierarchy and click an entity under any subscene, the trigger event will fail.

    E.g. the bullet hits enemies and is destroyed. But, after clicking the Entities Hierarchy and then clicking player entity, the bullet will suddenly pass through enemies.

    Nothing has changed, not exiting play mode. Just clicking any entity in the Entities Hierarchy, the trigger disappear.

    But the job is still running which I am sure because debug.log still shows in console.

    I have no idea why. I think it is a bug.

    Unity 2022.0616.112.5806.
    Entities 1.0.0-exp.12
     
  2. piginaust

    piginaust

    Joined:
    May 23, 2022
    Posts:
    14
    The issue is resolved in exp 15 version. Close case.