#Disconnecting Players

1 messages · Page 1 of 1 (latest)

boreal mountain
#

I don't know when UserDisconnect() is getting called but you will probably need to call Shutdown() first before you switch scenes

vapid ice
#

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);
        }```
boreal mountain
#

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

vapid ice
boreal mountain