#Disconnecting Players
1 messages · Page 1 of 1 (latest)
I don't know when UserDisconnect() is getting called but you will probably need to call Shutdown() first before you switch scenes
My teammate is the one editing the code and he's gone for a little rn so ill send this to him and get back to u asap
We moved the load scene after disconnect which removed all errors but when the host disconnects, the host gets loaded back into the scene but the client doesnt,
public async Task UserDisconnect()
{
var nm = GetNetworkManager;
if(!nm.IsListening || nm.ShutdownInProgress)
return;
HideLobbyCode();
if(nm.IsHost)
nm.ConnectionApprovalCallback -= HandleConnectionApproval;
await LeaveOrDeleteLobby();
_connectionStatus = ConnectionStatus.UserDisconnect;
nm.Shutdown();
LoadOfflineScene();
}```
@boreal mountain
the user disconnect method is just being called when u press escape
and this is what we use to load scenes
private void LoadOfflineScene()
{
if(GetNetworkManager.IsHost)
SwitchSceneServerRpc(offlineSceneName, true);
else
SwitchSceneServerRpc(offlineSceneName, false);
}
[ServerRpc]
private void SwitchSceneServerRpc(string sceneName, bool useNetworkSceneManager = true)
{
if(!enableSceneManagement)
return;
if(useNetworkSceneManager)
GetNetworkManager.SceneManager.LoadScene(sceneName, LoadSceneMode.Single);
else
SceneManager.LoadScene(sceneName, LoadSceneMode.Single);
}```
You are already disconnected when LoadOfflineScene() is run so you don't need any RPCs or the NetworkManager at all. It won't be tunning at this point anyways
But load offline scene only gets called once, when the host leaves so only the host will be brought back, how can we make it so that everyone gets loaded back?
call that function in the OnClientDisconnect callback