Search Unity

Job Dependenies in JobComponentSystem

Discussion in 'Entity Component System' started by Superheftig, Mar 19, 2019.

  1. Superheftig

    Superheftig

    Joined:
    Mar 4, 2015
    Posts:
    14
    I have two JobComponentSystem A and B and I put [UpdateAfter(typeof(A))] on top of the B.

    When i create the jobs inside of: protected override JobHandle OnUpdate(JobHandle inputDeps), i put the inputDeps into the schedule method like this: job.Schedule(1000, 32, inputDeps);

    It still seems that job B does not wait until A is finished. I pass into both jobs the same NativeArray. A is writing to it while B is reading from it and i get the follwing errors:

    InvalidOperationException: The previously scheduled job JobComponentSystemA:Job writes to the NativeArray Job.ExtraData. You are trying to schedule a new job JobComponentSystemB:Job, which reads from the same NativeArray (via Job.ExtraData). To guarantee safety, you must include JobComponentSystemA:Job as a dependency of the newly scheduled job.

    If i add: jobHandle.Complete() directly atfer the first job is scheduled, it works. But this is not what i want!

    So what is the right way to manage depenendies between two JobComponentSystem?
     
  2. Attatekjir

    Attatekjir

    Joined:
    Sep 17, 2018
    Posts:
    23
    The tag [UpdateAfter(typeof(A))] just means the OnUpdate() method of B will be after the OnUpdate() method of A. So job of system A will be scheduled earlier than job of system B. The order in which the jobs are actually run is determined by inner working of the Jobsystem.

    The actual error you are receiving is because NativeContainers dependencies are not automatically passed between systems. See https://forum.unity.com/threads/passing-nativecontainers-between-systems-dependency-issue.642868/
    Also: The search function on this forum is usefull ;)
     
  3. Superheftig

    Superheftig

    Joined:
    Mar 4, 2015
    Posts:
    14