Game Project
A game project is the base level of project. It contains a game.
A game project is the base level of project. It contains a game.
Startup
The game project generally defines a startup scene in its project settings. This scene is usually loaded first - before any other scene.
Depending on the game you're making, you might want an intro or menu scene. You can set the startup scene to your menu scene, and have your menu load your main game scene after the user chooses to play.
It's totally valid to not have a menu or intro scene though, and just jump straight into the game.
Maps
If your game is capable of loading maps from the main menu then that map is loaded instead of your startup scene. This presents a problem for your game - because none of your game stuff is in that map. You probably want to spawn UI and game manager stuff in the map, in order to let people play.
The way to do this is to create a [GameObjectSystem] that will spawn in all that stuff. Here's an example where we spawn it in from another scene.
public sealed class MyGameManager : GameObjectSystem<MyGameManager>, 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 );
}
}
Referenced API
Canonical API pages mentioned in this guide.
Allows creation of a system that always exists in every scene, is hooked into the scene's lifecycle, and is disposed when the scene is disposed.
Allows listening to events related to scene startup. This should really only apply to GameObjectSystem's because components won't have been spawned/created when most of this is invoked.
Called after the scene is loaded. In game only, on the host only.
Load from the provided `Sandbox.SceneFile`. This will not load the scene for other clients in a multiplayer session, you should instead use `Sandbox.Game.ChangeScene(Sandbox.SceneLoadOptions)` if you want to bring other clients.
Load from the provided `Sandbox.SceneLoadOptions`. This will not load the scene for other clients in a multiplayer session, you should instead use `Sandbox.Game.ChangeScene(Sandbox.SceneLoadOptions)` if you want to bring other clients.
No summary available.
The base collection. Game binds have this set to the common binds.