Search Unity

How to ensure that a system is the first system to run among other systems?

Discussion in 'Entity Component System' started by davenirline, Dec 7, 2018.

  1. davenirline

    davenirline

    Joined:
    Jul 7, 2010
    Posts:
    987
    I'm making a system that collects commands in an EntityCommandBuffer outside of ECS context (MonoBehaviours). When the systems updates executes, I want a system to playback the collected commands as a starting system. This way, the subsequent systems can filter the newly applied components and entities.

    The current way to do this is to add [UpdateAfter] in every system that I made. This is not maintenance friendly. I would eventually go this route if there's no other way. So is there a way to make a system run first?
     
    Last edited: Dec 7, 2018
  2. eizenhorn

    eizenhorn

    Joined:
    Oct 17, 2016
    Posts:
    2,685
    You can group systems by UpdateInGroup and set UpdateBefore this group for your "first" system. But yes attribute chains it's only way.
     
  3. 5argon

    5argon

    Joined:
    Jun 10, 2013
    Posts:
    1,555
    You may exploit the default that all systems are placed in the Update step, so put your playback system in Initialization step. It works as long as you avoid using Initialization step. *Currently in my game EndFrameBarrier is down below the Update step even though it has Initialization step attribute, not sure what is going on. From the code comment :


    Code (CSharp):
    1.     [UpdateBefore(typeof(Initialization))]
    2.     [Preserve]
    3.     public class EndFrameBarrier : BarrierSystem
    4.     {
    5.     }