SceneLoadData

The Data Class needed for the SceneManager to know how to handle loading a scene.

General

Loading scenes of all types depend upon SceneLoadData. The SceneLoadData class contains information about what scenes to load, how to load them, which objects to move to new scenes, and more. You can view the SceneLoadData API here.

Default Values

//Default Values
SceneLoadData sld = new SceneLoadData()
{
    PreferredActiveScene = null,
    SceneLookupDatas = new SceneLookupData[0],
    MovedNetworkObjects = new NetworkObject[0],
    ReplaceScenes = ReplaceOption.None,
    Params = new LoadParams()
    {
        ServerParams = new object[0],
        ClientParams = new byte[0]
    },
    Options = new LoadOptions()
    {
        AutomaticallyUnload = true,
        AllowStacking = false,
        LocalPhysics = LocalPhysicsMode.None,
        ReloadScenes = false, //Obsolete, Comming Soon.
        Addressables = false
    }
};
PreferredActiveScene

Preferred Active Scene will allow you to choose what scene will be active on the server and client. Currently this sets both client and server to the SceneLookupData provided.

If left with the default value of null, the first valid scene loaded will become the ActiveScene.

SceneLookupDatas

This Array is populated with scenes you would like to load, depending on the parameters you pass into the SceneLoadData when constructed.

See Loading Scenes for examples.

MovedNetworkObjects

NetworkObjects can be moved when loading new scenes, such as if you want to move a player to a different scene as you load the new scene. You may include an array of NetworkObjects to move to the new scenes. NetworkObjects within this array will be moved to the first scene specified in SceneLookupData. See Persisting NetworkObjects for more details on what type of NetworkObjects you are allowed to move.

ReplaceScenes

Like the Unity SceneManager when loading a single scene, ReplaceScenes allows you to replace currently loaded scenes with new ones. There are a variety of options to use. See Replacing Scenes Section of Loading Scenes guide for more details and examples.

Params

Params are an optional way to assign data to your scene loads/unloads. This data will be available within Scene Events, Information used in Params can be useful for storing information about the scene load/unload and referencing it later when the scene load/unload completes.

ServerParams

ServerParams are only included on the server side, and are not networked. It is an array of objects, meaning you can send anything you want. However when accessing the Params through event args, you will have to cast the object to the data you want.

ClientParams

ClientParams is a byte array which may contain anything, and will be sent to clients when they receive the load scene instructions. Clients can access the ClientParams within the scene change events.

Options

You may further enhance how you load/unload scenes with Options.

AutomaticallyUnload

  • When set to true scenes will be unloaded automatically on the server when there are no more connections present. This is the default behaviour.

  • When set to false the scene will remain if connections leave the scene unexpected, such as being disconnected.

  • However, discussed in UnloadSceneData, this behavior can be overriden using the UnloadOptions of UnloadSceneData.

  • Only scenes loaded for connections will be automatically unloaded when emptied.

  • Global scenes can only be unloaded using ReplaceScenes or by calling unload on them.

AllowStacking

  • When AllowStacking remains false the SceneManager will not stack scenes in your SceneLoadDatas.

  • If true then scenes can be stacked (loaded multiple times).

  • In the SceneLookupData section it was mentioned that if a Scene reference or handle is specified then the SceneManager will favor loading a scene using a scene handle. When you would like to load connections into the same stacked scene over multiple load calls, you will populate your SceneLookupDatas by Scene reference or handle.

  • See Scene Stacking for more detail and examples

LocalPhysics

  • LocalPhysics is a Unity property that lets you determine how physics are simulated in your scenes.

  • Generally if you are stacking scenes you will want to set a LocalPhysics mode so that stacked scenes do not collide with each other.

Addressables

  • Addressables is only used as a reference and performs no additional functionality.

  • You may set this value to know if a scene is loading using addressables, without having to create Params.

Last updated