ModelRenderer draws a model at the object’s position. A RigidBody adds physics simulation. Your own components hold your game logic — movement, health, weapons, and anything else your game needs.
Adding components
In the editor
Select a GameObject in the scene, then click Add Component in the Inspector. Search for the component type you want and click to add it.In code
CallAddComponent<T>() on a GameObject reference:
GetOrAddComponent<T>() when you want to ensure the component exists but don’t want to add a duplicate:
Querying components
Retrieve components from a GameObject and its hierarchy using the methods below:Specialized queries with FindMode
For more control over which GameObjects and states to include, useComponents.Get<T> and Components.GetAll<T> directly with FindMode flags:
Component references
Declare component references as properties to wire them up in the editor or enforce dependencies:Removing and destroying components
CallDestroy() on the component instance. You cannot reuse a destroyed component.
DestroyGameObject() or GameObject.Destroy().
Component lifecycle methods
Override these methods in your component class to hook into the s&box update cycle:OnLoad (async)
OnLoad (async)
Called after deserialization, before the scene starts. The loading screen stays open until all
OnLoad tasks complete. Use this for heavy setup work like procedural generation.OnValidate
OnValidate
Called whenever a property changes in the editor, and after deserialization. Use this to enforce property limits or update derived state.
OnAwake
OnAwake
Called once when the component is created, but only if its parent GameObject is enabled. This fires after deserialization and loading.
OnStart
OnStart
Called when the component is enabled for the first time. Always runs before the first
OnFixedUpdate.OnEnabled
OnEnabled
Called each time the component is enabled (including after being disabled and re-enabled).
OnUpdate
OnUpdate
Called every frame. Use this for frame-rate-dependent logic like reading input or updating visual effects.
OnPreRender
OnPreRender
Called every frame just before rendering. Not called on dedicated servers. This fires after animation bones have been calculated, making it a good place to attach things to bones.
OnFixedUpdate
OnFixedUpdate
Called every fixed timestep. Use this for physics-dependent logic like player movement to keep behaviour consistent regardless of frame rate.
OnDisabled
OnDisabled
Called each time the component is disabled.
OnDestroy
OnDestroy
Called when the component is destroyed.
A component’s callbacks only run when the component is enabled and its GameObject and all ancestor GameObjects are also enabled.
Execution order
s&box does not guarantee the order in which the same callback fires across different GameObjects. If you need predictable cross-object ordering, use a GameObjectSystem instead.Async in components
By default, async tasks in s&box run on the main thread, similar to coroutines. Useasync Task methods to write sequential async logic:
Task.WhenAll:
_:
Component events
You can broadcast and listen to events across your scene using interfaces. Events reach all active components and GameObjectSystems — they are not sent over the network.Defining an event interface
Posting an event
Listening to an event
Implement the interface on any component:Advanced broadcasting
Scene.RunEvent lets you target any type — not just custom event interfaces:
Component interfaces
s&box provides built-in interfaces you can implement on your components for common behaviours.ExecuteInEditor
ExecuteInEditor
Runs
OnAwake, OnEnabled, OnDisabled, OnUpdate, and OnFixedUpdate while in editor edit mode — useful for preview components.ICollisionListener
ICollisionListener
React to physics collisions on this collider or rigidbody.
| Method | When it’s called |
|---|---|
OnCollisionStart | When this object starts touching another collider |
OnCollisionUpdate | Once per physics step while touching another collider |
OnCollisionStop | When this object stops touching another collider |
ITriggerListener
ITriggerListener
React to objects entering and leaving a trigger volume.
| Method | When it’s called |
|---|---|
OnTriggerEnter | When a collider enters the trigger |
OnTriggerExit | When a collider stops touching the trigger |
IDamageable
IDamageable
Mark a component as something that can receive damage. Other code can find and call
OnDamage on it without knowing the specific type.INetworkListener and INetworkSpawn
INetworkListener and INetworkSpawn
React to network events.
INetworkListener handles general network events; INetworkSpawn handles object spawn events. See the Networking section for details.PlayerController reference
ThePlayerController component is a ready-to-use first- and third-person player controller. Add it to a GameObject and you can walk around your scene immediately with no code required.
How it works
At its core,PlayerController is a special RigidBody. It participates in the physics system and exposes the same properties (velocity, mass, etc.) while adding movement controls.
Input
Built-in keyboard, mouse, and controller support. Override
EyeAngles and WishVelocity in OnFixedUpdate if you want to drive it from custom input.Camera
Built-in first- and third-person camera that you can toggle with a configured button. Disable the camera tab if you manage your own camera.
Animator
Built-in animator for Citizen-compatible AnimGraphs. Disable the animator tab if you provide your own animation logic.
The input, camera, and animator features are all optional. Right-click any tab in the Inspector to disable features you don’t need.
Listening to PlayerController events
ImplementPlayerController.IEvents on a sibling component to react to player events and modify camera behaviour:
TemporaryEffect
TheTemporaryEffect component is designed for prefabs that contain particle effects and sounds. It monitors all child effects using the ITemporaryEffect interface and destroys the GameObject automatically once every effect has finished playing.
Add TemporaryEffect to any prefab that should clean itself up — for example, an explosion effect that spawns at a point and then disappears. You can implement ITemporaryEffect on your own components to make them compatible with this system.