Skip to main content

Class NetworkSceneManager

NetworkSceneManager is an optional component that helps keep scene in sync between server and client. The loads scenes as instructed by the . The controls the currently active Scene and any additive Load/Unload. when a client connect NetworkSceneManager will send a message telling the new client to load the scene that is active on the server

Inheritance
System.Object
Syntax
public class NetworkSceneManager : MonoBehaviour

Fields

Client

Declaration
public NetworkClient Client

Server

Declaration
public NetworkServer Server

ServerObjectManager

Declaration
public ServerObjectManager ServerObjectManager

ClientObjectManager

Declaration
public ClientObjectManager ClientObjectManager

SendAdditiveScenesOnAuthenticate

Declaration
public bool SendAdditiveScenesOnAuthenticate

DontDestroy

Sets the NetworksSceneManagers GameObject to DontDestroyOnLoad. Default = true.

Declaration
public bool DontDestroy

SceneLoadingAsyncOperationInfo

Information on any scene that is currently being loaded.

Declaration
public AsyncOperation SceneLoadingAsyncOperationInfo

Properties

ActiveScenePath

The path of the current active scene. If using additive scenes this will be the first scene. Value from

Declaration
public string ActiveScenePath { get; }

ServerSceneData

Collection of scenes and which player's are in those scenes.

Declaration
public IReadOnlyDictionary<Scene, HashSet<INetworkPlayer>> ServerSceneData { get; }

OnClientStartedSceneChange

Event fires when the Client starts changing scene.

Declaration
public SceneChangeStartedEvent OnClientStartedSceneChange { get; }

OnClientFinishedSceneChange

Event fires after the Client has completed its scene change.

Declaration
public SceneChangeFinishedEvent OnClientFinishedSceneChange { get; }

OnServerStartedSceneChange

Event fires before Server changes scene.

Declaration
public SceneChangeStartedEvent OnServerStartedSceneChange { get; }

OnServerFinishedSceneChange

Event fires after Server has completed scene change.

Declaration
public SceneChangeFinishedEvent OnServerFinishedSceneChange { get; }

OnPlayerSceneReady

Event fires On the server, after Client sends to the server

Declaration
public PlayerSceneChangeEvent OnPlayerSceneReady { get; }

Methods

Start()

Declaration
public virtual void Start()

OnDestroy()

Declaration
public virtual void OnDestroy()

IsPlayerInScene(Scene, INetworkPlayer)

Check whether or not the player is in a specific scene or not.

Declaration
public bool IsPlayerInScene(Scene scene, INetworkPlayer player)
Parameters
TypeNameDescription
ScenesceneThe scene we want to check in.
Mirage.INetworkPlayerplayerThe player we want to check for.
Returns
TypeDescription
System.BooleanReturns true or false if the player is in the scene specified.

ScenesPlayerIsIn(INetworkPlayer)

What scene is this specific player currently in.

Declaration
public Scene[] ScenesPlayerIsIn(INetworkPlayer player)
Parameters
TypeNameDescription
Mirage.INetworkPlayerplayerThe player we want to check against.
Returns
TypeDescription
Scene[]Returns back a array of scene's the player is currently in.

ScenesPlayerIsInNonAlloc(INetworkPlayer, List<Scene>)

Declaration
public void ScenesPlayerIsInNonAlloc(INetworkPlayer player, List<Scene> scenes)
Parameters
TypeNameDescription
Mirage.INetworkPlayerplayer
System.Collections.Generic.List<Scene>scenes

ClientStartSceneMessage(INetworkPlayer, SceneMessage)

Received message from server to start loading scene or scenes.

Default implementation is to load main activate scene server is using and load any other additive scenes in background and notify event handler. If this is not intended behavior you need please override this function.

Declaration
public virtual void ClientStartSceneMessage(INetworkPlayer player, SceneMessage message)
Parameters
TypeNameDescription
Mirage.INetworkPlayerplayer
Mirage.SceneMessagemessage

ClientFinishedLoadingSceneMessage(INetworkPlayer, SceneReadyMessage)

Received message from server that it has finished loading the scene.

Default implementation will set AllowSceneActivation = true and invoke event handler. If this is not good enough intended behavior then override this method.

Declaration
protected virtual void ClientFinishedLoadingSceneMessage(INetworkPlayer player, SceneReadyMessage message)
Parameters
TypeNameDescription
Mirage.INetworkPlayerplayerThe player who sent the message.
Mirage.SceneReadyMessagemessageThe message data coming back from server.

ClientNotReadyMessage(INetworkPlayer, SceneNotReadyMessage)

Received message that player is not ready.

Default implementation is to set player to not ready.

Declaration
protected virtual void ClientNotReadyMessage(INetworkPlayer player, SceneNotReadyMessage message)
Parameters
TypeNameDescription
Mirage.INetworkPlayerplayerThe player that is currently not ready.
Mirage.SceneNotReadyMessagemessageThe message data coming in.

SetSceneIsReady()

Signal that the client connection is ready to enter the game. This could be for example when a client enters an ongoing game and has finished loading the current scene. The server should respond to the message with an appropriate handler which instantiates the players object for example.

Declaration
public void SetSceneIsReady()

ServerLoadForPlayers(String, IEnumerable<INetworkPlayer>, Boolean, SceneOperation)

Loads a scene on players but NOT on server Note: does not load for Host player, they should be loaded using server methods instead

Declaration
public void ServerLoadForPlayers(string scenePath, IEnumerable<INetworkPlayer> players, bool shouldClientLoadOrUnloadNormally, SceneOperation sceneOperation = SceneOperation.Normal)
Parameters
TypeNameDescription
System.StringscenePath
System.Collections.Generic.IEnumerable<Mirage.INetworkPlayer>players
System.BooleanshouldClientLoadOrUnloadNormally
Mirage.SceneOperationsceneOperation

ServerSceneUnLoading(Scene, IEnumerable<INetworkPlayer>)

Unload a specific scene from server and clients

Declaration
public void ServerSceneUnLoading(Scene scene, IEnumerable<INetworkPlayer> players)
Parameters
TypeNameDescription
ScenesceneWhat scene do we want to tell server and clients to unload.
System.Collections.Generic.IEnumerable<Mirage.INetworkPlayer>playersThe players we want to tell to unload the scene.

ServerSceneUnLoadingAsync(Scene, IEnumerable<INetworkPlayer>)

Unload a specific scene from server and clients

Declaration
public UniTask ServerSceneUnLoadingAsync(Scene scene, IEnumerable<INetworkPlayer> players)
Parameters
TypeNameDescription
ScenesceneWhat scene do we want to tell server and clients to unload.
System.Collections.Generic.IEnumerable<Mirage.INetworkPlayer>playersThe players we want to tell to unload the scene.
Returns
TypeDescription
Cysharp.Threading.Tasks.UniTask

ServerLoadSceneNormal(String, Nullable<LoadSceneParameters>)

Allows server to fully load in a new scene and override current active scene.

Declaration
public void ServerLoadSceneNormal(string scenePath, LoadSceneParameters? sceneLoadParameters = default(LoadSceneParameters? ))
Parameters
TypeNameDescription
System.StringscenePathThe full path to the scene file or the name of the scene.
System.Nullable<LoadSceneParameters>sceneLoadParametersWhat settings should we be using for physics scene loading.

ServerLoadSceneNormalAsync(String, Nullable<LoadSceneParameters>)

Allows server to fully load in a new scene and override current active scene.

Declaration
public UniTask ServerLoadSceneNormalAsync(string scenePath, LoadSceneParameters? sceneLoadParameters = default(LoadSceneParameters? ))
Parameters
TypeNameDescription
System.StringscenePathThe full path to the scene file or the name of the scene.
System.Nullable<LoadSceneParameters>sceneLoadParametersWhat settings should we be using for physics scene loading.
Returns
TypeDescription
Cysharp.Threading.Tasks.UniTask

ServerLoadSceneAdditively(String, IEnumerable<INetworkPlayer>, Boolean, Nullable<LoadSceneParameters>)

Allows server to fully load in another scene on top of current active scene.

Declaration
public void ServerLoadSceneAdditively(string scenePath, IEnumerable<INetworkPlayer> players, bool shouldClientLoadNormally = false, LoadSceneParameters? sceneLoadParameters = default(LoadSceneParameters? ))
Parameters
TypeNameDescription
System.StringscenePathThe full path to the scene file or the name of the scene.
System.Collections.Generic.IEnumerable<Mirage.INetworkPlayer>playersCollection of player's that are receiving the new scene load.
System.BooleanshouldClientLoadNormallyShould the clients load this additively too or load it full normal scene change.
System.Nullable<LoadSceneParameters>sceneLoadParametersWhat settings should we be using for physics scene loading.

ServerLoadSceneAdditivelyAsync(String, IEnumerable<INetworkPlayer>, Boolean, Nullable<LoadSceneParameters>)

Allows server to fully load in another scene on top of current active scene.

Declaration
public UniTask ServerLoadSceneAdditivelyAsync(string scenePath, IEnumerable<INetworkPlayer> players, bool shouldClientLoadNormally = false, LoadSceneParameters? sceneLoadParameters = default(LoadSceneParameters? ))
Parameters
TypeNameDescription
System.StringscenePathThe full path to the scene file or the name of the scene.
System.Collections.Generic.IEnumerable<Mirage.INetworkPlayer>playersCollection of player's that are receiving the new scene load.
System.BooleanshouldClientLoadNormallyShould the clients load this additively too or load it full normal scene change.
System.Nullable<LoadSceneParameters>sceneLoadParametersWhat settings should we be using for physics scene loading.
Returns
TypeDescription
Cysharp.Threading.Tasks.UniTask

ServerUnloadSceneAdditively(Scene, IEnumerable<INetworkPlayer>)

Allows server to fully unload a scene additively.

Declaration
public void ServerUnloadSceneAdditively(Scene scene, IEnumerable<INetworkPlayer> players)
Parameters
TypeNameDescription
ScenesceneThe scene handle which we want to unload additively.
System.Collections.Generic.IEnumerable<Mirage.INetworkPlayer>playersCollection of player's that are receiving the new scene unload.

ServerUnloadSceneAdditivelyAsync(Scene, IEnumerable<INetworkPlayer>)

Allows server to fully unload a scene additively.

Declaration
public UniTask ServerUnloadSceneAdditivelyAsync(Scene scene, IEnumerable<INetworkPlayer> players)
Parameters
TypeNameDescription
ScenesceneThe scene handle which we want to unload additively.
System.Collections.Generic.IEnumerable<Mirage.INetworkPlayer>playersCollection of player's that are receiving the new scene unload.
Returns
TypeDescription
Cysharp.Threading.Tasks.UniTask

OnServerAuthenticated(INetworkPlayer)

When player authenticates to server we send a message to them to load up main scene and any other scenes that are loaded on server.

Default implementation takes main activate scene as main and any other loaded scenes and sends it to player's Please override this function if this is not intended behavior for you.

Declaration
protected virtual void OnServerAuthenticated(INetworkPlayer player)
Parameters
TypeNameDescription
Mirage.INetworkPlayerplayerThe current player that finished authenticating.

OnServerPlayerDisconnected(INetworkPlayer)

When player disconnects from server we will need to clean up info in scenes related to user. Default implementation we loop through list of scenes and find where this player was in and removed them from list.

Declaration
protected virtual void OnServerPlayerDisconnected(INetworkPlayer disconnectedPlayer)
Parameters
TypeNameDescription
Mirage.INetworkPlayerdisconnectedPlayer

SetAllClientsNotReady(IEnumerable<INetworkPlayer>)

Marks all connected clients as no longer ready.

All clients will no longer be sent state synchronization updates.
The player&apos;s clients can call ClientManager.Ready() again to re-enter the ready state.
This is useful when switching scenes.
Declaration
public void SetAllClientsNotReady(IEnumerable<INetworkPlayer> players = null)
Parameters
TypeNameDescription
System.Collections.Generic.IEnumerable<Mirage.INetworkPlayer>players

SetClientNotReady(INetworkPlayer)

Sets a player as not ready and removes all visible objects Players that are not ready will not be sent spawn message or state updates. Players that are not ready do not receive spawned objects or state synchronization updates. They client can be made ready again by calling SetClientReady().

Declaration
public void SetClientNotReady(INetworkPlayer player)
Parameters
TypeNameDescription
Mirage.INetworkPlayerplayerThe player to make not ready.

GetSceneByPathOrName(String)

Let's us get scene by full path or by its name.

Declaration
public Scene GetSceneByPathOrName(string scenePath)
Parameters
TypeNameDescription
System.StringscenePathThe path or name representing the scene.
Returns
TypeDescription
SceneReturns back correct scene data.