Search Unity

Get System Update Order

Discussion in 'Entity Component System' started by EvansT, May 31, 2018.

  1. EvansT

    EvansT

    Joined:
    Jan 22, 2015
    Posts:
    22
    I am writing a deterministic simulation where there is a Tick() method on each system which gets executed 10 times per second irrespective of frame-rate. This Tick() method will be present on all systems and must called on them in the same order as the order in which OnUpdate() is called. Is there a way I can get the list of systems in the order Update() will be called on them taking into account dependencies, UpdateBefore, UpdateAfter etc? Or if there is a better way to implement this, I'd love to hear that as well.
     
    Last edited: Jun 4, 2018
  2. FMark92

    FMark92

    Joined:
    May 18, 2017
    Posts:
    1,243
    Would it not be easier to use existing update sequence by limiting frame rate and using FixedUupdate()?

    But I'm sure there is a way of achieving exactly what you wrote.

    Maybe if you record the sequence in which updates ran and use that?
     
  3. EvansT

    EvansT

    Joined:
    Jan 22, 2015
    Posts:
    22
    I want OnUpdate() to run as well. That will be used to execute code that does not need to be deterministic - such as animations and particles. Game-play/simulation code must be inside Tick().

    Sounds like a hack :) I'd prefer a more robust approach.
     
    Last edited: Jun 4, 2018
  4. EvansT

    EvansT

    Joined:
    Jan 22, 2015
    Posts:
    22
    The simplest solution seems to be:

    Create a TickSystem with a method IsCurrentUpdateATick().
    All other systems will call this method to check if the current OnUpdate() call is where deterministic code must be executed. This also seems to be more in line with Unity ECS's approach of not having instant callbacks, and instead doing everything through the OnUpdate() method.