Search Unity

Can't have Entities.ForEach with a job dependency?

Discussion in 'Data Oriented Technology Stack' started by victor_apihtin, Mar 7, 2021.

  1. victor_apihtin

    victor_apihtin

    Joined:
    Mar 2, 2021
    Posts:
    26
    .Schedule and .ScheduleParallel have an optional JobHandle parameter, but trying to schedule a ForEach after an arbitrary job gives an error clusterfluck.

    Code (CSharp):
    1. InvalidOperationException: The previously scheduled job DetectIdleAgentSystem:DetectIdleAgentJob writes to the NativeArray DetectIdleAgentJob.needsPath. You must call JobHandle.Complete() on the job DetectIdleAgentSystem:DetectIdleAgentJob, before you can write to the NativeArray safely.
    Only calling .Complete() on the job and scheduling without a dependency makes ForEach to work
     
  2. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    9,108
    For each Utomati ally takes dependency.
    You can optionally pas it into schedule, and return it from the job.

    You need to look at your Native Array DetectIdleAgentJob.needsPath.
    You probably write in and read in another job. Or something similar.
     
  3. victor_apihtin

    victor_apihtin

    Joined:
    Mar 2, 2021
    Posts:
    26
    Yeah, okay, the secret was if you pass a dependency in, you need to re-assign this.Dependency from the return. My bad
     
    jasons-novaleaf likes this.
unityunity