Search Unity

How to complete only required job in chunk iteration when working with JobComponentSystem?

Discussion in 'Entity Component System' started by 5argon, Nov 17, 2018.

  1. 5argon

    5argon

    Joined:
    Jun 10, 2013
    Posts:
    1,555
    I have several JobComponentSystem working in chain, finally at the final system which is also a JobComponentSystem but in its OnUpdate I used chunk iteration. At the point where I call `GetNativeArray` with a read-only ArchetypeChunkComponentType, it would complain that a previous job hasn't finished yet so I cannot access the array.

    I could call inputDeps.Complete(), but will that complete other unrelated jobs before this system too?

    Ideally, I think there should be a way to tell that inputDeps JobHandle "I am going to access this component, so please complete only jobs that are working on this component."

    *note : This system running chunk iteration does not have any component group (I used a cached EntityArchetypeQuery), so I think it is impossible for this JCS to "know" what it needs without some special routines to inform the system?
     
    Last edited: Nov 17, 2018
  2. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
    inputDeps is all dependencies of all the components being read / written by this system.

    In the case of ArchetypeChunk you declare what you are reading / writing with calls to:
    ComponentSystem.GetArchetypeChunkComponentType();

    So inputDeps as a dependency is the minimal set of dependencies for that specific system. The idea being that if two systems work on different types then their jobs can run in parallel to each other.
     
  3. 5argon

    5argon

    Joined:
    Jun 10, 2013
    Posts:
    1,555
    I see, I just realized GetArchetypeChunkComponentType has a permanent "register" effect on a system like GetComponentGroup on OnCreateManager. (I was not thinking so because I have to do it in every OnUpdate) In that case completing the deps as a whole is good enough. Thank you.