Class NetworkSceneManager
Main class for managing network scenes when EnableSceneManagement is enabled. Uses the SceneEventMessage message to communicate SceneEventData between the server and client(s)
Implements
Inherited Members
Namespace: Unity.Netcode
Assembly: solution.dll
Syntax
public class NetworkSceneManager : IDisposable
Fields
PostSynchronizationSceneUnloading
When enabled and ClientSynchronizationMode is Additive, any scenes not synchronized with the server will be unloaded unless VerifySceneBeforeUnloading returns true. This provides more granular control over which already loaded client-side scenes not synchronized with the server should be unloaded.
Declaration
public bool PostSynchronizationSceneUnloading
Field Value
Type | Description |
---|---|
bool |
Remarks
If the VerifySceneBeforeUnloading delegate callback is not set then any scene loaded on the just synchronized client will be unloaded. One scenario is a synchronized client is disconnected for unexpected reasons and attempts to reconnect to the same network session but still has all scenes that were loaded through server synchronization (initially or through scene events). However, during the client disconnection period the server unloads one (or more) of the scenes loaded and as such the reconnecting client could still have the now unloaded scenes still loaded. Enabling this flag coupled with assignment of the assignment of the VerifySceneBeforeUnloading delegate callback provides you with the ability to keep scenes loaded by the client (i.e. UI etc) while discarding any artifact scenes that no longer need to be loaded.
VerifySceneBeforeLoading
Delegate handler defined by NetworkSceneManager.VerifySceneBeforeLoadingDelegateHandler that is invoked before the server or client loads a scene during an active netcode game session.
Declaration
public NetworkSceneManager.VerifySceneBeforeLoadingDelegateHandler VerifySceneBeforeLoading
Field Value
Type | Description |
---|---|
NetworkSceneManager.VerifySceneBeforeLoadingDelegateHandler |
Remarks
Client Side: In order for clients to be notified of this condition you must assign the VerifySceneBeforeLoading delegate handler.
Server Side: LoadScene(string, LoadSceneMode) will return SceneEventProgressStatus.
VerifySceneBeforeUnloading
Client Side Only:
Delegate handler defined by NetworkSceneManager.VerifySceneBeforeUnloadingDelegateHandler that is only invoked when the client
is finished synchronizing and when ClientSynchronizationMode is set to Additive.
Declaration
public NetworkSceneManager.VerifySceneBeforeUnloadingDelegateHandler VerifySceneBeforeUnloading
Field Value
Type | Description |
---|---|
NetworkSceneManager.VerifySceneBeforeUnloadingDelegateHandler |
Properties
ActiveSceneSynchronizationEnabled
When enabled, the server or host will synchronize clients with changes to the currently active scene
Declaration
public bool ActiveSceneSynchronizationEnabled { get; set; }
Property Value
Type | Description |
---|---|
bool |
ClientSynchronizationMode
This setting changes how clients handle scene loading when initially synchronizing with the server.
See: SetClientSynchronizationMode(LoadSceneMode)
Declaration
public LoadSceneMode ClientSynchronizationMode { get; }
Property Value
Type | Description |
---|---|
LoadSceneMode |
Remarks
LoadSceneMode.Single: All currently loaded scenes on the client will be unloaded and the
server's currently active scene will be loaded in single mode on the client unless it was already
loaded.
LoadSceneMode.Additive: All currently loaded scenes are left as they are and any newly loaded
scenes will be loaded additively. Users need to determine which scenes are valid to load via the
VerifySceneBeforeLoading and, if PostSynchronizationSceneUnloading is
set, VerifySceneBeforeUnloading callback(s).
Methods
DisableValidationWarnings(bool)
When set to true, this will disable the console warnings about a scene being invalidated.
Declaration
public void DisableValidationWarnings(bool disabled)
Parameters
Type | Name | Description |
---|---|---|
bool | disabled | true/false |
Dispose()
Handle NetworkSeneManager clean up
Declaration
public void Dispose()
LoadScene(string, LoadSceneMode)
Server side: Loads the scene name in either additive or single loading mode. When applicable, the AsyncOperation is delivered within the SceneEvent via OnSceneEvent
Declaration
public SceneEventProgressStatus LoadScene(string sceneName, LoadSceneMode loadSceneMode)
Parameters
Type | Name | Description |
---|---|---|
string | sceneName | the name of the scene to be loaded |
LoadSceneMode | loadSceneMode | how the scene will be loaded (single or additive mode) |
Returns
Type | Description |
---|---|
SceneEventProgressStatus | SceneEventProgressStatus (Started means it was successful) |
SetClientSynchronizationMode(LoadSceneMode)
Declaration
public void SetClientSynchronizationMode(LoadSceneMode mode)
Parameters
Type | Name | Description |
---|---|---|
LoadSceneMode | mode |
UnloadScene(Scene)
Server Side: Unloads an additively loaded scene. If you want to unload a Single mode loaded scene load another Single scene. When applicable, the AsyncOperation is delivered within the SceneEvent via the OnSceneEvent
Declaration
public SceneEventProgressStatus UnloadScene(Scene scene)
Parameters
Type | Name | Description |
---|---|---|
Scene | scene |
Returns
Type | Description |
---|---|
SceneEventProgressStatus | SceneEventProgressStatus (Started means it was successful) |
Events
OnLoad
Invoked when a Load event is started by the server.
Note: The server and connected client(s) will always receive this notification.
*** Do not start new scene events within scene event notification callbacks.
Declaration
public event NetworkSceneManager.OnLoadDelegateHandler OnLoad
Event Type
Type | Description |
---|---|
NetworkSceneManager.OnLoadDelegateHandler |
OnLoadComplete
Invoked when a LoadComplete event is generated by a client or server.
Note: The server receives this message from all clients (including itself).
Each client receives their own notification sent to the server.
*** Do not start new scene events within scene event notification callbacks.
Declaration
public event NetworkSceneManager.OnLoadCompleteDelegateHandler OnLoadComplete
Event Type
Type | Description |
---|---|
NetworkSceneManager.OnLoadCompleteDelegateHandler |
OnLoadEventCompleted
Invoked when a LoadEventCompleted event is generated by the server.
This event signifies the end of an existing Load event as it pertains
to all clients connected when the event was started. This event signifies that all clients (and server) have
finished the Load event.
Note: this is useful to know when all clients have loaded the same scene (single or additive mode)
*** Do not start new scene events within scene event notification callbacks.
Declaration
public event NetworkSceneManager.OnEventCompletedDelegateHandler OnLoadEventCompleted
Event Type
Type | Description |
---|---|
NetworkSceneManager.OnEventCompletedDelegateHandler |
OnSceneEvent
Subscribe to this event to receive all SceneEventType notifications.
For more details review over SceneEvent and SceneEventType.
Alternate Single Event Type Notification Registration Options
To receive only a specific event type notification or a limited set of notifications you can alternately subscribe to
each notification type individually via the following events:
- OnLoad Invoked only when a Load event is being processed
- OnUnload Invoked only when an Unload event is being processed
- OnSynchronize Invoked only when a Synchronize event is being processed
- OnLoadEventCompleted Invoked only when a LoadEventCompleted event is being processed
- OnUnloadEventCompleted Invoked only when an UnloadEventCompleted event is being processed
- OnLoadComplete Invoked only when a LoadComplete event is being processed
- OnUnloadComplete Invoked only when an UnloadComplete event is being processed
- OnSynchronizeComplete Invoked only when a SynchronizeComplete event is being processed
Declaration
public event NetworkSceneManager.SceneEventDelegate OnSceneEvent
Event Type
Type | Description |
---|---|
NetworkSceneManager.SceneEventDelegate |
OnSynchronize
Invoked when a Synchronize event is started by the server
after a client is approved for connection in order to synchronize the client with the currently loaded
scenes and NetworkObjects. This event signifies the beginning of the synchronization event.
Note: The server and connected client(s) will always receive this notification.
This event is generated on a per newly connected and approved client basis.
*** Do not start new scene events within scene event notification callbacks.
Declaration
public event NetworkSceneManager.OnSynchronizeDelegateHandler OnSynchronize
Event Type
Type | Description |
---|---|
NetworkSceneManager.OnSynchronizeDelegateHandler |
OnSynchronizeComplete
Invoked when a SynchronizeComplete event is generated by a client.
Note: The server receives this message from the client, but will never generate this event for itself.
Each client receives their own notification sent to the server. This is useful to know that a client has
completed the entire connection sequence, loaded all scenes, and synchronized all NetworkObjects.
*** Do not start new scene events within scene event notification callbacks.
Declaration
public event NetworkSceneManager.OnSynchronizeCompleteDelegateHandler OnSynchronizeComplete
Event Type
Type | Description |
---|---|
NetworkSceneManager.OnSynchronizeCompleteDelegateHandler |
OnUnload
Invoked when a Unload event is started by the server.
Note: The server and connected client(s) will always receive this notification.
*** Do not start new scene events within scene event notification callbacks.
Declaration
public event NetworkSceneManager.OnUnloadDelegateHandler OnUnload
Event Type
Type | Description |
---|---|
NetworkSceneManager.OnUnloadDelegateHandler |
OnUnloadComplete
Invoked when a UnloadComplete event is generated by a client or server.
Note: The server receives this message from all clients (including itself).
Each client receives their own notification sent to the server.
*** Do not start new scene events within scene event notification callbacks.
Declaration
public event NetworkSceneManager.OnUnloadCompleteDelegateHandler OnUnloadComplete
Event Type
Type | Description |
---|---|
NetworkSceneManager.OnUnloadCompleteDelegateHandler |
OnUnloadEventCompleted
Invoked when a UnloadEventCompleted event is generated by the server.
This event signifies the end of an existing Unload event as it pertains
to all clients connected when the event was started. This event signifies that all clients (and server) have
finished the Unload event.
Note: this is useful to know when all clients have unloaded a specific scene. The LoadSceneMode will
always be Additive for this event.
*** Do not start new scene events within scene event notification callbacks.
Declaration
public event NetworkSceneManager.OnEventCompletedDelegateHandler OnUnloadEventCompleted
Event Type
Type | Description |
---|---|
NetworkSceneManager.OnEventCompletedDelegateHandler |