Search Unity

ECS Error missing JobHandle.Complete()

Discussion in 'Entity Component System' started by BobyUnity, Apr 5, 2020.

  1. BobyUnity

    BobyUnity

    Joined:
    Apr 9, 2019
    Posts:
    30
    Hello together!

    I´m new to this forum. I´m currently trying out the ECS / DOTS Stuff and try to find as many resources as possible. Unfortunately its not super easy to do so. The documentation is not very abundant atm (or I didn´t find the right spot to read) so any tips are highly appreciated. Also stuff gets old pretty fast. How do you guys keep track?

    I used Youtube atm for the most part and followed along the following video:


    For him the code works but for me it fails. I used exactly the same packages that he used with Unity 2019.3.0f6. The Errorcode is the following:

    InvalidOperationException: The previously scheduled job PickupSystem:TriggerJob writes to the NativeArray TriggerJob.UserJobData.rotationSpeedEntities. You must call JobHandle.Complete() on the job PickupSystem:TriggerJob, before you can read from the NativeArray safely.

    I already tried stuff from other threads as you can tell by seeing the out comments.
    At the moment I dont understand what to do. Also I dont understand

    The code for the trigger system is the following:

    Code (CSharp):
    1. using Unity.Collections;
    2. using Unity.Entities;
    3. using Unity.Jobs;
    4. using Unity.Physics.Systems;
    5. using Unity.Physics;
    6.  
    7.  
    8. public class PickupSystem : JobComponentSystem
    9. {
    10.     private BeginInitializationEntityCommandBufferSystem bufferSystem;
    11.     private BuildPhysicsWorld buildPhysicsWorld;
    12.     private StepPhysicsWorld stepPhysicsWorld;
    13.  
    14.     protected override void OnCreate()
    15.     {
    16.         bufferSystem = World.GetOrCreateSystem<BeginInitializationEntityCommandBufferSystem>();
    17.         buildPhysicsWorld = World.GetOrCreateSystem<BuildPhysicsWorld>();
    18.         stepPhysicsWorld = World.GetOrCreateSystem<StepPhysicsWorld>();
    19.     }
    20.  
    21.     protected override JobHandle OnUpdate(JobHandle inputDeps)
    22.     {
    23.         TriggerJob triggerjob = new TriggerJob
    24.         {
    25.             rotationSpeedEntities = GetComponentDataFromEntity<RotationSpeedData>(),
    26.             entitiesToDelete = GetComponentDataFromEntity<DeleteTag>(),
    27.             commandBuffer = bufferSystem.CreateCommandBuffer()
    28.  
    29.         };
    30.  
    31.         JobHandle varJobHandle = triggerjob.Schedule(stepPhysicsWorld.Simulation, ref buildPhysicsWorld.PhysicsWorld, inputDeps);
    32.         //bufferSystem.AddJobHandleForProducer(varJobHandle);
    33.         //varJobHandle.Complete();
    34.         return varJobHandle;
    35.     }
    36.  
    37.     private struct TriggerJob : ITriggerEventsJob
    38.     {
    39.         public ComponentDataFromEntity<RotationSpeedData> rotationSpeedEntities;
    40.         [ReadOnly] public ComponentDataFromEntity<DeleteTag> entitiesToDelete;
    41.         public EntityCommandBuffer commandBuffer;
    42.  
    43.         public void Execute(TriggerEvent triggerEvent)
    44.         {
    45.             TestEntityTrigger(triggerEvent.Entities.EntityA, triggerEvent.Entities.EntityB);
    46.             TestEntityTrigger(triggerEvent.Entities.EntityB, triggerEvent.Entities.EntityA);
    47.         }
    48.  
    49.         private void TestEntityTrigger(Entity entity1, Entity entity2)
    50.         {
    51.             if (rotationSpeedEntities.HasComponent(entity1))
    52.             {
    53.                 if (entitiesToDelete.HasComponent(entity2)) { return; }
    54.                 commandBuffer.AddComponent(entity2, new DeleteTag());
    55.                
    56.             }
    57.  
    58.         }
    59.  
    60.     }
    61. }
    62.  
     
  2. AndrewS_2000

    AndrewS_2000

    Joined:
    Dec 5, 2017
    Posts:
    1
    Hi, did you manage to find a solution for this as I am having the same issue?