menu_bookDocumentation
Component Lifecycle Methods Reference
Component Lifecycle Methods
s&box Components have a well-defined lifecycle with specific methods you can override for different phases of initialization and updates.
Key Lifecycle Methods
| Method | When Called | Use Case |
|---|---|---|
| OnLoad() | After deserialization, async | Procedural generation, asset loading during load screen |
| OnValidate() | When properties change in editor | Enforce property limits, validate data |
| OnAwake() | Once when component created | One-time initialization |
| OnStart() | First time component enabled | Setup that runs before first FixedUpdate |
| OnEnabled() | When component becomes enabled | Subscribe to events, start processes |
| OnUpdate() | Every frame | Per-frame logic |
| OnPreRender() | Every frame before rendering | Animation-dependent updates |
| OnFixedUpdate() | Every fixed timestep | Physics, player movement |
| OnDisabled() | When component disabled | Unsubscribe, cleanup |
| OnDestroy() | When component destroyed | Final cleanup |
Example: Procedural Level Loading
CSHARP
public sealed class LevelGenerator : Component
{
protected override async Task OnLoad()
{
LoadingScreen.Title = "Generating Level...";
// Generate terrain
await GenerateTerrain();
// Place objects
await PlaceObjects();
LoadingScreen.Title = "Finalizing...";
await Task.DelayRealtimeSeconds(0.5f);
}
}Important Notes
- Component is only enabled if its GameObject and all ancestors are enabled
- OnFixedUpdate is recommended for player movement to reduce trace count and avoid small-delta issues
- OnPreRender is not called on dedicated servers
Was this helpful?