skip to Main Content

Is there a specific order in which the update method is called for components added in Flame? For example, in Unity, the LateUpdate method is available to ensure certain updates, like the camera update, are executed last.

Is it called in the order it was added? Or is the order random?

2

Answers


  1. Checkout Order of Execution documentation: https://docs.unity3d.com/6000.0/Documentation/Manual/execution-order.html

    You can change order of execution like in this thread with an Attribute: https://stackoverflow.com/questions/27928474/programmatically-define-execution-order-of-scripts#:~:text=you%20can%20use%20the%20attribute%3A

    I like to have in general just one Monobehaviour and the rest are normal C# classes (until you need some prefabs and scripts which do change just one single object) and the main Monobehaviour controls which Update is called first. Anyway you could also use Events for some particular cases.

    Login or Signup to reply.
  2. The order of update is decided depending on the priority of the component, and if two components have the same priority they are updated in the order that they were added. But, this only applies to sibling components, the component tree updates start in the root and then it traverses down to the leaf components.

      /// This method traverses the component tree and calls [update] on all its
      /// children according to their [priority] order, relative to the
      /// priority of the direct siblings, not the children or the ancestors.
      void updateTree(double dt) {
        update(dt);
        _children?.forEach((c) => c.updateTree(dt));
      }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search