Search Unity

Multiple frame Job

Discussion in 'Entity Component System' started by saarg, Mar 22, 2019.

  1. saarg

    saarg

    Joined:
    Mar 9, 2017
    Posts:
    31
    Hi,

    I'm currently experimenting with the new ECS & Jobs system and I was wondering if there was any way to run a job in a JobComponentSystem over n frames.
    For example on a simple boid flocking simulation what would be a way to run the movement job every frame and the Steering Job run over 10 frames?

    Thanks
     
  2. NoDumbQuestion

    NoDumbQuestion

    Joined:
    Nov 10, 2017
    Posts:
    186
    Code (CSharp):
    1.         if (Time.frameCount % 10 == 0) {
    2.             inputDeps= new JobComponentSystem().Schedule(this);
    3.         }
     
    daniilkorotin, JakHussain and saarg like this.
  3. saarg

    saarg

    Joined:
    Mar 9, 2017
    Posts:
    31
    Thanks, I did not realize we could start a job not depending on another job completion.

    Your username is perfect.
     
    daniilkorotin and JakHussain like this.
  4. 5argon

    5argon

    Joined:
    Jun 10, 2013
    Posts:
    1,555
    Just in case, the returned `JobHandle` from `JobComponentSystem`'s `OnUpdate` will be force completed immediately on the next frame. So if you managed to run a job on every 10th frame for example and put that in the line with the dependency chain, the next 11th frame it will be completed. (So not "over" 10 frames but rather every 10 frames + over 1 frame)
     
  5. shortwanabelaker

    shortwanabelaker

    Joined:
    Jul 10, 2018
    Posts:
    3
    Is there a way to start a job (in ecs) and then have the job start itself and have all of this in a way that is not dependent on the update function?
     
  6. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,761
    Can't start a job from a job

    * you kind of can with hacks and unsafe code for very specific circumstances (mostly non Unity related) but if you don't know how you definitely should not be doing this
     
    MNNoxMortem likes this.