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

Execute multiple systems manually

Discussion in 'Entity Component System' started by e199, Sep 24, 2018.

  1. e199

    e199

    Joined:
    Mar 24, 2015
    Posts:
    101
    Hi

    I'm coming from Entitas ECS and I want to clarify a few things for me.

    1) Imagine you have networking game where you do client-prediction and you need to do rollbacks and execute all local input commands which are not yet simulated on server.
    To do that in Entitas we can group systems into a systems class and execute it multiple times

    Code (CSharp):
    1. public class MovementSystems : Systems
    2. {
    3.     public MovementSystems (Contexts contexts, Services services)
    4.     {
    5.         Add(new ModifyAccelerationWithInputSystem(contexts));
    6.         Add(new ModifyAccelerationWithForces(contexts));
    7.         Add(new ModifyVelocityWithAccelerationSystem(contexts));
    8.  
    9.         Add(new SimulatePhysicsSystem(contexts));
    10.     }
    11. }
    12. ////
    13. var movement = new MovementSystems(...);
    14. ////
    15. for(int frame = serverFrame; i<clientFrame; i++)
    16. {
    17.     applyInputForFrame(frame);
    18.     movement.Execute(); //To manually execute all child systems
    }

    Easy, right?
    What is the correct way to do it with built-in ECS and jobs?

    2) Is it possible that I will schedule jobs before jobs from the previous frames ended?
    In a way what it will lower performance as it need to do more and more jobs until it freezes?
     
  2. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
    You can call ComponentSystem.Update() in any order you like. So a utility method that just manually invokes the relevant systems is the way to go.

    The Job system is architected so that you can run ComponentSystems in any order you like, dependencies will be correctly handled and behave as if the code was running on the main thread, giving the maximum parallelism given the order of the systems.