Scene Management

Using the Scene Module in PurrNet is as easy as changing scene with Unity's default scene manager. But there is also some more depth to understanding the logic of players in scenes.

Scene management needs to be handled on the Server, so everything below is needed to be read with that context!

Loading Scenes

For ease of use, you can simply call the LoadSceneAsync with the scene name as a string, or the scene id.

//Loads scene with default settings
networkManager.sceneModule.LoadSceneAsync("sceneName");

There are multiple overloads to the LoadSceneAsync method (see image below), such as directly setting the load mode directly, using Unity LoadSceneParameters, or adding custom PurrNet settings.

Overloads for the LoadSceneAsync

You can also load a scene with custom scene settings called PurrSceneSettings, see example below:

//Loads scene with custom settings
var settings = new PurrSceneSettings();
settings.isPublic = true; //Default setting - Has all connections automatically switch scene
settings.mode = LoadSceneMode.Single; //Default setting - Unloads all other scenes
networkManager.sceneModule.LoadSceneAsync("sceneName", settings);

PurrSceneSettings

The PurrSceneSettings is a struct of setting for your scene loading. This has the following values:

  • mode : The Unity SceneLoadMode, so whether it should be additive or single

  • physicsMode : The Unity LocalPhysicsMode to load with

  • isPublic : Whether the scene automatically pulls all players into the scene or not

Unloading scenes

Unloading scenes with PurrNet is as easy as calling the unload of the scene, similar to Unity's own scene management. This will unload the scene for all clients in the scene, as well as the server.

networkManager.sceneModule.UnloadSceneAsync("sceneName");
Overloads for UnloadSceneAsync

The UnloadSceneOptions are a Unity class, which by default is None when using the UnloadSceneAsync.

Last updated