menu_bookDocumentation

Execution Order - s&box Documentation

calendar_today May 5, 2026 schedule ~1 min read person patrickjr verified 50

Execution Order

Understanding the order in which component methods are called.

Flowchart

Component lifecycle follows a specific order:

  1. Constructor — Object created
  2. OnAwake — First initialization (once)
  3. OnEnabled — Component becomes active
  4. OnStart — Scene is ready
  5. OnUpdate — Every frame
  6. OnFixedUpdate — Physics timestep
  7. OnDisabled — Component deactivated
  8. OnDestroy — Cleanup

Order Within Stages

Within each stage, components execute in order:

  1. By default, execution order is undefined
  2. Use [Order(int)] attribute to control:
CSHARP
[Order( 100 )]
public class EarlyComponent : Component { }

[Order( 500 )]
public class LateComponent : Component { }

Lower numbers execute first.

GameObjectSystem Order

Systems also have execution stages:

CSHARP
public class MySystem : GameObjectSystem
{
    public MySystem( Scene scene ) : base( scene )
    {
        ListenToStage( Stage.Startup, 0, OnStartup );
        ListenToStage( Stage.Update, 100, OnUpdate );
    }
}

Best Practices

  • Use [Order()] sparingly
  • Don't rely on execution order between unrelated components
  • Use events/messages for cross-component communication
  • Initialize in OnAwake, start logic in OnStart

Common Mistakes

  • Assuming components update in creation order
  • Doing heavy work in constructors
  • Not handling disabled state properly
  • Cross-component dependencies without proper ordering
Was this helpful?