menu_bookDocumentation
GameObjectSystem - s&box Scene Documentation
GameObjectSystem
GameObjectSystems are global systems that operate on groups of GameObjects. Unlike Components which are attached to single GameObjects, systems can process many objects and run at specific stages of the frame.
Implementation
Create a system by inheriting from GameObjectSystem:
CSHARP
[Group( "MyGame" )] // For organization in editor
public class MyGameSystem : GameObjectSystem
{
public MyGameSystem( Scene scene ) : base( scene )
{
// Initialize the system
ListenToStage( Stage.Update, PreUpdate );
ListenToStage( Stage.FinishUpdate, PostUpdate );
}
void PreUpdate()
{
// Runs early in the update loop
}
void PostUpdate()
{
// Runs at the end of the update loop
}
}Access
Access your system from components:
CSHARP
var mySystem = Scene.GetSystem<MyGameSystem>();
mySystem?.DoSomething();Stages and Order
Systems listen to specific stages with ListenToStage:
| Stage | When It Runs |
|---|---|
| Stage.Startup | Scene initialization |
| Stage.Update | Main update loop |
| Stage.FinishUpdate | End of frame |
| Stage.PhysicsStep | Physics simulation |
| Stage.Render | Rendering |
Configuration
Systems can have configurable properties:
CSHARP
[ConVar( "mygame_max_enemies" )]
public static int MaxEnemies { get; set; } = 50;Systems are powerful for global game logic like:
- Spawn managers
- Wave systems
- Global game state
- Performance monitoring
- Analytics tracking
Was this helpful?