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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Problem with Job Dependencies: "You must call JobHandle.Complete() on the job"

Discussion in 'Entity Component System' started by swejk, Aug 29, 2019.

  1. swejk

    swejk

    Joined:
    Dec 22, 2013
    Posts:
    20
    Hello,

    I am experiencing issue with scheduling jobs where I am writting to the component in the first job and reading from the same component in the second job. I am correctly passing job handle from the first job to second job but I am still seeing the error suggesting I have to call Compete() on the first job.

    Is it a bug or am I doing something wrong ?

    Here is code:
    Code (CSharp):
    1.          
    2.            
    3. private struct UpdateBarValuesJob : IJobForEach<HUDBar, HUDUnitOwner>
    4. {
    5.  
    6.     [ReadOnly]
    7.     public ComponentDataFromEntity<Stamina> StaminaFromEntity;
    8.     [ReadOnly]
    9.     public ComponentDataFromEntity<Health> HealthFromEntity;
    10.     public void Execute(ref HUDBar bar, [ReadOnly] ref HUDUnitOwner owner)
    11.     {
    12.        ...
    13.      }
    14. }
    15.  
    16. private struct UpdateBarsJob : IJobForEachWithEntity_EBC<HUDBarItem, HUDBar>
    17. {
    18.     public EntityCommandBuffer.Concurrent Buffer;
    19.  
    20.     public void Execute(Entity entity, int index, [ReadOnly] DynamicBuffer<HUDBarItem> barItems, [ChangedFilter][ReadOnly] ref HUDBar bar)
    21.     {
    22.        ...
    23.     }
    24. }
    25.  
    26. protected override JobHandle OnUpdate(JobHandle inputDeps)
    27. {
    28.     inputDeps = new UpdateBarValuesJob
    29.     {
    30.         HealthFromEntity = GetComponentDataFromEntity<Health>(true),
    31.         StaminaFromEntity = GetComponentDataFromEntity<Stamina>(true)
    32.     }.Schedule(this, inputDeps);
    33.  
    34.     //inputDeps.Complete();
    35.    
    36.     inputDeps = new UpdateBarsJob
    37.     {
    38.         Buffer = _bufferSystem.CreateCommandBuffer().ToConcurrent()
    39.     }.Schedule(this, inputDeps);
    40.     _bufferSystem.AddJobHandleForProducer(inputDeps);
    41.     return inputDeps;
    42. }
    43.  
     
  2. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,648
    What you're doing looks fine. Are you sure it is this job causing the issue (not something in another system). If not only thing I can think of is the ChangedFilter but I don't feel like that should be an issue.
     
  3. swejk

    swejk

    Joined:
    Dec 22, 2013
    Posts:
    20
    You were right about ChangedFilter, removing it will get rid of issue. Though, why is it breaking jobs is a mystery to me.