Search Unity

How to get dependency from another system?

Discussion in 'Entity Component System' started by varnon, Jul 21, 2021.

  1. varnon

    varnon

    Joined:
    Jan 14, 2017
    Posts:
    52
    Hi all,

    I am considering scheduling some jobs (though Entities.ForEach or Job.WithCode) in one system (SystemBase) dependent on the completion of schedule jobs in another system (separate SystemBase class). I feel like it should be obvious, but I'm not having any luck with the docs or what I can find in the forums. I haven't had issues in the past with managing dependencies within a single SystemBase class, but clearly I'm missing something for cross-class dependency management.

    I would like to know how to do this in general, but my current use case would be multiple systems using the results of a spatial hashing system. The spatial hashing system writes to a NativeMultiHashMap. After this scheduled job is complete, other systems should be free to query from the map (read only).
     
  2. DreamingImLatios

    DreamingImLatios

    Joined:
    Jun 3, 2017
    Posts:
    4,264
    Dependency is just a combined JobHandle of all the ComponentTypes the system touches for the duration of Update() which includes OnStartRunning(), OnUpdate(), and OnStopRunning(). Really you want a JobHandle associated with the container in question. So store that JobHandle along with the container and always update that handle whenever you schedule a job against the container.

    If you want a solution that manages dependencies of containers automatically, I wrote such a mechanism in my framework: https://github.com/Dreaming381/Lati...e/Collection and Managed Struct Components.md
     
    Krajca likes this.