menu_bookDocumentation
Execution Order - s&box Documentation
Execution Order
Understanding the order in which component methods are called.
Flowchart
Component lifecycle follows a specific order:
- Constructor — Object created
- OnAwake — First initialization (once)
- OnEnabled — Component becomes active
- OnStart — Scene is ready
- OnUpdate — Every frame
- OnFixedUpdate — Physics timestep
- OnDisabled — Component deactivated
- OnDestroy — Cleanup
Order Within Stages
Within each stage, components execute in order:
- By default, execution order is undefined
- 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?