This guide outlines recommended steps when using the Multiplayer Services SDK to ensure your game cleanly disconnects from previous matches before starting a new one in multi-match game sessions
When using Multiplayer Sessions:
-
Always use
ISession.LeaveAsync()to leave a session.
This is the only correct method. It internally shuts down NGO (Netcode for GameObjects), awaitsOnClientStopped, and then callsDispose(), which restoresNetworkManager.NetworkConfig.
-
Do not call
NetworkManager.Shutdown()manually.
CallingLeaveAsync()automatically fires the SDK's internalOnManagerStoppedsequence, which includes a full teardown of the NetworkManager. A manual shutdown will conflict with this execution and cause unexpected behaviour.
-
Manage
NetworkManager.SceneManagersubscriptions carefully.
The SceneManager creates a new instance each time NGO starts. Any subscriptions made on the lobby DA session (such asOnLoadEventCompleted) become dead references afterLeaveAsync(). You must unsubscribe from all scene events before callingLeaveAsync(), and then resubscribe to the new SceneManager once the new session is ready.
-
Verify session closure via Network Manager events.
Even ifLeaveAsync()executes fully, you should subscribe to the Network Manager eventsOnClientStoppedandOnServerStoppedto guarantee that the previous match is entirely closed before attempting to join another session.
-
Utilize a delayed start approach.
You can decouple session creation from netcode initialization by omitting.WithDirectNetwork()/.WithRelayNetwork()/.WithDistributedAuthorityNetwork()when creating a session. This allows you to group players before starting the network.
-
Initialize the network only when ready.
When your lobby is ready to start connecting, start the network usingStartDirectNetworkAsync(DirectNetworkOptions). This is especially helpful for transitioning players between matches without dropping them from matchmaking groups. This approach works with both RelayNetwork and DistributedAuthorityNetwork.