Documentation 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 is the abstract base class for all s&box game scripts. You attach components to GameObjects to give them behaviour. The engine calls lifecycle methods on your component at the right moment — OnAwake once at startup, OnEnabled and OnDisabled when the active state changes, OnUpdate every frame, and so on. This page documents every public and protected member you can override or use.
Your own components inherit from
Component (or a subclass). You never instantiate Component directly — use go.AddComponent<T>() or go.GetOrAddComponent<T>().Declaring a component
Core properties
The
GameObject this component belongs to. Accessing any component property before the component is attached (i.e. before the engine calls OnAwake) will give you null.Shortcut for
GameObject.Scene. The scene this component lives in.Shortcut for
GameObject.Transform. Position, rotation, and scale of the owning GameObject.Shortcut for
GameObject.Components. The component list of the owning GameObject.Shortcut for
GameObject.Tags. The tag set of the owning GameObject.The enable state of this component. Setting
Enabled = false does not destroy the component — it pauses lifecycle callbacks. The component stays attached to the GameObject.Enabled tells you what the component wants to be. Use Active to determine whether the component is actually ticking (i.e. the GameObject hierarchy is also enabled).true when this component is enabled and all ancestor GameObjects are enabled. Only Active components receive OnUpdate, OnFixedUpdate, and similar callbacks.true when this component is still attached to a GameObject and belongs to a scene. Returns false after Destroy() has been called.Bitmask of
ComponentFlags controlling serialisation and editor behaviour. See ComponentFlags.A
TaskSource whose token is automatically cancelled when the component’s GameObject is disabled or destroyed. Use for async code that should stop cleanly.Lifecycle methods
Lifecycle methods are called by the engine in a deterministic order. Override only what you need.- Flow diagram
- Method reference
OnAwake
GameObject and scene to be present — equivalent to a constructor, but with the guarantee that the scene is ready.
OnEnabled
OnAwake. Use it to register for events, start coroutines, or set up state that must be torn down in OnDisabled.
OnStart
OnUpdate, after OnEnabled. Runs at the start of the first frame the component is active. Use it for logic that depends on other components having completed their OnAwake and OnEnabled calls.
OnUpdate
Time.Delta gives the elapsed seconds since the last frame. Not called on dedicated servers.
OnFixedUpdate
Time.Delta is the fixed step duration. Use for physics manipulation and anything that must be framerate-independent.
OnPreRender
SceneModel) that must be in sync with transforms before the draw call.
OnDisabled
OnEnabled — tear down anything set up there (event subscriptions, etc.).
OnDestroy
GameObject and discarded. After this method returns, IsValid is false.
OnValidate
[Property] is changed in the editor. Use it to clamp values, recalculate derived state, or update visual representations in response to property edits.
OnParentChanged
GameObject changes. Useful for components that cache a reference to the parent or need to adjust their state based on hierarchy position.
OnParentDestroy
GameObject is being destroyed. Override to re-parent or clean up before the parent disappears.
OnTagsChanged
GameObject or any ancestor change.
Invoke (delayed callback)
action after secondsDelay seconds. The callback is silently dropped if the component is no longer active or the CancellationToken is cancelled.
Component access shortcuts
All of these are convenience wrappers aroundComponents. See GameObject — component methods for the full parameter documentation; the signatures are identical.
Destroying a component
Destroy
GameObject. OnDisabled then OnDestroy are both called. After this call, IsValid returns false.
DestroyGameObject
GameObject?.Destroy(). Destroys the owning GameObject and all of its children and components.
ComponentFlags
ComponentFlags is a bitmask you can set on component.Flags to control engine behaviour.
Hides this component in the editor’s component inspector.
This component is not serialised to disk when the scene is saved.
This component is excluded from the networked scene snapshot.
This component is skipped when the
GameObject is cloned via Clone().Shows advanced (normally hidden) properties in the component inspector.
Action Graph event hooks
The following[Property] callbacks let you wire Action Graph nodes directly to component events without subclassing:
| Property | Fires when |
|---|---|
OnComponentEnabled | Component becomes active |
OnComponentStart | First frame after becoming active |
OnComponentUpdate | Every frame while active |
OnComponentFixedUpdate | Every physics step while active |
OnComponentDisabled | Component becomes inactive |
OnComponentDestroy | Component is destroyed |
See also
GameObject
The object that components attach to.
Scene
The scene container; use
Scene.GetAll<T>() to find components across the whole scene.Scripting basics
Practical guide to writing and attaching components.