Components are the building blocks of every s&box game object. ADocumentation 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.
GameObject on its own is just a transform in the hierarchy; every piece of functionality — movement, rendering, physics, audio — is provided by one or more components attached to that object. This page covers how components work, their lifecycle callbacks, and how to add and query them from code.
What is a Component?
Component is an abstract C# class. You create behaviour by inheriting from it and overriding the lifecycle methods you need. Components live on a GameObject via its Components list and share the transform and scene of that object.
GameObject is active will have their update methods called by the engine automatically — no registration required.
The component lifecycle
The engine calls the following virtual methods in a defined order. Override only the ones you need.OnAwake
Called once, the first time the component becomes active. Use this for one-time initialisation that must run before
OnEnabled.OnStart
Called once before the very first
OnUpdate, after OnEnabled. Use this for anything that depends on other components having finished their OnAwake.OnEnabled
Called every time the component transitions from inactive to active — either at first activation or after being re-enabled. Runs after
OnAwake on first activation.OnUpdate
Called every rendered frame while the component is active.
Time.Delta contains the time in seconds since the last frame.OnUpdate does not run on a dedicated server. Use OnFixedUpdate for simulation logic that must run server-side.OnFixedUpdate
Called on a fixed time step that matches the physics tick rate.
Time.Delta is the fixed interval. Use this for physics forces, networked simulation, and anything that must be deterministic.OnDisabled
Called when the component becomes inactive — either because
Enabled was set to false, or because an ancestor GameObject was disabled.Lifecycle order summary
| Callback | When it runs | Frequency |
|---|---|---|
OnAwake | First activation | Once |
OnStart | Before first OnUpdate | Once |
OnEnabled | Each time component becomes active | Per activation |
OnUpdate | Every render frame (not on dedicated server) | Per frame |
OnFixedUpdate | Every physics tick | Per tick |
OnDisabled | Each time component becomes inactive | Per deactivation |
OnDestroy | On permanent removal | Once |
The Enabled and Active properties
Enabled is what you set. Active is what the engine uses. A component is Active only when it is enabled and every ancestor GameObject in the hierarchy is also enabled.
Attaching components to a GameObject
- Generic method (recommended)
- Get or add
- Via ComponentList
Querying components
UseGetComponent<T> and related helpers to find components on a GameObject or in the surrounding hierarchy.
On the same object
Searching up and down the hierarchy
Using FindMode for fine-grained control
Components.GetAll<T>(FindMode) accepts a FindMode flags enum that lets you combine search scope and enabled state:
TryGet pattern
Destroying a component
Destroy() removes just the component, leaving the GameObject and other components intact. To destroy the whole object, call DestroyGameObject().
Component flags
ComponentFlags control serialisation and networking behaviour:
| Flag | Effect |
|---|---|
Hidden | Component is not shown in the editor inspector |
NotSaved | Component is not saved to disk |
NotNetworked | Component is excluded from the network scene snapshot |
NotCloned | Component is skipped when cloning the GameObject |
Next steps
Scene and GameObject
Review how GameObjects are structured and found in the scene.
Prefabs
Package configured GameObjects into reusable prefab assets.