Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

[Possible Bug] Job Dependencies Unexpected Behavior (Feature?)

Discussion in 'Entity Component System' started by slim_trunks, Oct 16, 2018.

  1. slim_trunks

    slim_trunks

    Joined:
    Dec 31, 2017
    Posts:
    41
    I came across some unexpected behavior while using the Job System. At first I though I made a mistake but I did some isolated tests and was able to reproduce the problem.

    I attached five test scripts that illustrate what I mean. I put them on an empty GameObject in a new Scene and activated them one after the other (all others disabled). Unity version is 2018.3.0b4, Jobs 0.0.7-preview.5, Collections 0.0.9-preview.8 and Mathematics 0.0.12-preview.19.

    Here is my commentary and thought process for every test:
    - DependencyTest1.cs
    This is a reduced version of what I'm doing in my project. Two jobs processing arrays, the first one more expensive than the second with the second job depending on the first one. This behaves as expected. JobOne and JobTwo are interleaved in the profiler window.

    - DependencyTest2.cs
    Now the unexpected behavior starts appearing. Making JobTwo depend on JobOne AND default(JobHandle) causes the jobs to stop being interleaved. Every JobOne gets executed before every JobTwo. Is this to be expected?

    - DependencyTest3.cs
    This is what I really want to do (in some form) in my project. Instead of depending on JobOne and default, JobTwo now depends on JobOne and the JobOne from a previous iteration. The behavior is still the same.

    - DependencyTest4.cs
    I read somewhere that to regain control of the resources a job uses one has to call Complete on it. This is known. But is this also the case for job dependency chains? I tried to also queue up the JobOne handles and call Complete on them in LateUpdate like I do with the JobTwo Handles. Still the same behavior as before.

    - DependencyTest5.cs
    Now I just call Complete on every JobOne Handle without checking IsComplete. This causes some of them to be executed on the main thread but the jobs are still not interleaved. Every JobOne still executes before every JobTwo.

    I know it's a lot but there's really just small changes from script to script. If I made a mistake in my code, or my model of the Job System is incomplete please let me know.
    If this is unexpected then it might be a bug.
     

    Attached Files: