Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Does calling update on TransformSystemGroup wait for execution to complete?

Discussion in 'Entity Component System' started by Fancisco_Greco, Apr 3, 2021.

  1. Fancisco_Greco

    Fancisco_Greco

    Joined:
    Jan 26, 2021
    Posts:
    20
    I'm calling
    Code (CSharp):
    1. world.GetExistingSystem<TransformSystemGroup>().Update();
    from a MonoBehaviour and I was wondering if the scheduled jobs wait for their execution to complete or do I have to somehow wait for them manually?
     
  2. DreamingImLatios

    DreamingImLatios

    Joined:
    Jun 3, 2017
    Posts:
    3,983
    The jobs won't be forced to complete but their dependencies will be tracked by the ECS world as usual. So the EntityManager is fair game after that Update call.
     
    Fancisco_Greco likes this.
  3. Fancisco_Greco

    Fancisco_Greco

    Joined:
    Jan 26, 2021
    Posts:
    20
    Interesting, I wanted to access LocalToWorld afterwards using the EntityManager but I'm getting inconsistent results, is there a way to force the dependencies to complete? If I add a stopwatch and wait for some time after the Update the problem goes away.
     
  4. DreamingImLatios

    DreamingImLatios

    Joined:
    Jun 3, 2017
    Posts:
    3,983
    EntityManager should automatically force all scheduled jobs touching LocalToWorld to complete when you access LocalToWorld. I'm not sure how a stopwatch is helping you unless you are stalling on the main thread.
     
    Fancisco_Greco likes this.
  5. Fancisco_Greco

    Fancisco_Greco

    Joined:
    Jan 26, 2021
    Posts:
    20
    Yeah I used the stopwatch to stall the main thread, I guess that for some reason the scheduled jobs are not completing when I access LocalToWorld, will see if I can get a minimal repro working, thank you!
     
  6. vildauget

    vildauget

    Joined:
    Mar 10, 2014
    Posts:
    120
    My guess is that the observed behavior can be caused by the fact that a job doesn't start as soon as it's scheduled.

    Options to consider could be to,
    - run "jobHandle.Complete()" if you could get hold of the job handle for the system. Though, I didn't find any API for that.
    - if you got the handle, you could also choose to only do the Monobavior part if "jobHandle.IsCompleted"
    - if you can live with a frame old data, just change the order, do whatever you want to do with they system's data first, then run .Update() on the system, to have refreshed data next frame.
    - run "World.DefaultGameObjectInjectionWorld.EntityManager.CompleteAllJobs();" after the .Update(). It should beat the wait timer, and you know it's updated.
     
    Fancisco_Greco likes this.