Every game object in s&box gets its behaviour from components — C# classes that extendDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/facepunch/sbox-public/llms.txt
Use this file to discover all available pages before exploring further.
Component and override lifecycle methods. This page explains how to structure a component, which lifecycle methods are available, how to expose properties to the editor, and how to use tags, flags, and serialization attributes.
Class structure
A component is an abstract partial class. To create your own, create a new.cs file and extend Component:
Lifecycle methods
The engine calls lifecycle methods on your component in a defined order. All methods are protected virtual and do nothing by default — override only what you need.OnAwake
Called once when the component is first initialized, before it is enabled. Use this for one-time setup that does not depend on other components being active.
OnEnabled
Called after
OnAwake, and again whenever the component transitions from disabled to enabled (including when the parent GameObject becomes active). Paired with OnDisabled.OnStart
Called once before the first
OnUpdate, but only after OnEnabled. This is the right place for logic that requires all components on the object to be initialized.OnUpdate
Called every frame when the component is active.
Time.Delta gives the elapsed time since the last frame.OnFixedUpdate
Called on a fixed interval determined by the scene — the same interval at which physics are ticked. Use this for physics-related logic.
Time.Delta inside OnFixedUpdate is the fixed timestep.OnPreRender
Called every frame before the scene is rendered. Not called on dedicated servers. Use this to update visual state (e.g. bone positions) before the camera draws.
Summary table
| Method | When called | Paired with |
|---|---|---|
OnAwake | Once, at initialization | — |
OnEnabled | On enable or parent becoming active | OnDisabled |
OnStart | Once, before the first OnUpdate | — |
OnUpdate | Every frame | — |
OnFixedUpdate | Fixed physics interval | — |
OnPreRender | Every frame, before rendering | — |
OnDestroy | Once, when destroyed | — |
Exposing properties to the editor
Decorate any field or property with[Property] to make it visible and editable in the s&box editor inspector. The engine serializes these values to the scene file automatically.
OnValidate
OnValidate is called immediately after the component is deserialized from a scene file, and whenever a property is changed in the editor. Use it to clamp values or recompute derived state:
Tags
Tags are string labels attached to aGameObject. Your component can read and modify them via the Tags property, which is a shortcut for GameObject.Tags.
Scene.GetAllObjects( true ) combined with tag checks to filter objects efficiently, or use GameObject.GetComponentsInChildren<T>() when you need to find components by type.
Component flags
ComponentFlags control editor and networking behaviour for a component instance. Set them on Flags:
RequireComponent
Decorate a property with[RequireComponent] to ensure the engine automatically finds or creates the required component on the same GameObject when your component is initialized. This removes the need for null checks at startup.
Rigidbody already exists on the GameObject, it is assigned. If not, one is created automatically.
ExecuteInEditor
By default, components do not run their lifecycle methods (includingOnUpdate) while the game is stopped in the editor. To opt in, implement the Component.ExecuteInEditor marker interface:
Accessing other components and the scene
From inside any component, you have direct shortcuts to the owning object and scene:Input system
Read player input inside OnUpdate with Input.Pressed and Input.Down.
Action Graphs
Wire up component lifecycle events to visual scripts without code.
Hot Reload
Understand how s&box applies code changes without restarting.
Component API reference
Full API reference for the Component base class.