ISceneStartup: Scene Initialization Events for Host and Client Setup
The ISceneStartup event interface in s&box allows Components and GameObjectSystems to listen to scene startup events. These run when pressing play in editor, loading a game, or joining a server.
public interface ISceneStartup : ISceneEvent<ISceneStartup>
{
void OnHostPreInitialize( SceneFile scene );
void OnHostInitialize();
void OnClientInitialize();
}OnHostPreInitialize
Called before the scene is loaded on the host. The scene is empty — only GameObjectSystems will see this since no Components exist yet.
OnHostInitialize
Called after the scene is loaded on the host. Good place to spawn common objects (cameras, game managers) and start hosting lobbies:
public sealed class MyGameManager : GameObjectSystem<GameManager>, ISceneStartup
{
public MyGameManager( Scene scene ) : base( scene ) { }
void ISceneStartup.OnHostInitialize()
{
var slo = new SceneLoadOptions();
slo.IsAdditive = true;
slo.SetScene( "scenes/engine.scene" );
Scene.Load( slo );
Networking.CreateLobby();
}
}OnClientInitialize
Called after scene load on both host and client (not on dedicated servers). Spawn client-side only things here, but mark them as not networked to prevent them being included in the scene snapshot sent to other clients.
"Host" here means the computer in charge: the player in singleplayer, a dedicated server, or a lobby host.