Search Unity

How does the job dependencies work in Unity ECS ?

Discussion in 'Entity Component System' started by Rup3rt, Nov 13, 2019.

  1. Rup3rt

    Rup3rt

    Joined:
    Nov 23, 2018
    Posts:
    7
    Hi, right now I'm designing a job system layout. And I want to be sure that those systems execute exactly in a determined order.
    I will put a simple example to make my question clearer.

    let's suppose that I have three systems:
    -SysA: reads from component X and writes to component Y.
    -SysB: reads from component Y and writes to Component Z.
    -SysC: reads from component Y and Z and writes to component X.

    now, in this case, I will need to run all of the SysA jobs then SysB jobs and finally the SysC jobs.
    So my question is, what are the methods to handle job dependencies between different job component systems?
     
  2. eizenhorn

    eizenhorn

    Joined:
    Oct 17, 2016
    Posts:
    2,685
    For order -
    UpdateBefore(typeof(T))
    UpdateAfter(typeof(T))
    attributes.
    For dependency - correct EntityQueries.
    SysA - EQ(ReadOnly(X), ReadWrite(Y))
    SysB - EQ(ReadOnly(Y), ReadWrite(Z))
    SysC - EQ(ReadOnly(Y),ReadOnly(Z), ReadWrite(X))
     
  3. Rup3rt

    Rup3rt

    Joined:
    Nov 23, 2018
    Posts:
    7
    Ok, I get that but I still don't understand where and how the dependencies declared in the querries are shared between systems.
    If I'm not mistaken, for what I've read, I believe that the dependencies of each system are shared to the rest of systems by the return value in the Update() function of the JobComponentSystem. Please correct me if I'm wrong because I'm not sure.
     
  4. DreamingImLatios

    DreamingImLatios

    Joined:
    Jun 3, 2017
    Posts:
    4,271
    A system keeps track of the queries used, and binds the returned JobHandle to them. The JobHandle knows nothing about the ECS types, and the ECS mechanism has no way of knowing which jobs the ECS types were used, so Unity needs both halves to sort out the dependencies.