Search Unity

Jobs in FixedUpdate

Discussion in 'Entity Component System' started by JooleanLogic, Jan 10, 2019.

  1. JooleanLogic

    JooleanLogic

    Joined:
    Mar 1, 2018
    Posts:
    447
    When/where is JobHandle.Complete() actually called for all the jobs scheduled in JobComponentSystem.OnUpdate()?
    If I want all my jobs to run within the FixedUpdate cycle, do I need to create a JobComponentSystem to complete these myself or is it enough to tell Unity that this system updates after FixedUpdate?

    Code (CSharp):
    1. [UpdateAfter(UnityEngine.Experimental.PlayerLoop.FixedUpdate)]
    2. class JobSystemA{}
    3.  
    4. [UpdateAfter(SystemA)]
    5. [UpdateAfter(UnityEngine.Experimental.PlayerLoop.FixedUpdate)]
    6. class JobSystemB{}
    7.  
    8. [UpdateAfter(UnityEngine.Experimental.PlayerLoop.FixedUpdate)]
    9. [UpdateAfter(JobSystemB)]
    10. class EndFixedUpdateSystem{
    11.     OnUpdate(JobHandle inputDeps){
    12.         inputDeps.Complete();
    13.         return inputDeps;
    14.     }
    15. }

    Is EndFixedUpdateSystem necessary? My systems are running within FixedUpdate and the jobs are running but I'm not sure if they're running per Update or per FixedUpdate.

    Is the JobHandle passed into OnUpdate() the same handle returned from the previous JobComponentSystem?
     
  2. mitaywalle

    mitaywalle

    Joined:
    Jul 1, 2013
    Posts:
    253
  3. xVergilx

    xVergilx

    Joined:
    Dec 22, 2014
    Posts:
    3,296
    Basically you'd need to implement some kind of barrier system, and then add a handle to it.
    Creating something similar to EndFrameBarrierSystem should do it. Look through the source, it might give you some ideas.

    Although I'm not that experienced with ECS implementation, so I might be wrong.