Hi, I am using the NetworkLobbyManager as a basis and I am having a strange error when disconnecting a client while mid-game.
The lobby setup, match browsing and joining works fine. I then set all clients ready to start the game, which also works and the game scene is loaded automatically. When I stop the server (end the build or stop the editor), all clients are thrown back into the lobby menu scene, as intended. If I stop the client (currently testing with only one client), the build running the server completely freezes and stops responding. This even happens in the Editor, which means I have to kill the editor via task manager.
Another strange thing is that the Game Player Prefab is instantiated, but it does not fire any of its events. Am I missing something fundamental?
Is it possible there is an infinite loop or something running in a client exit callback, such as OnLobbyServerDisconnect?
As for the second case, if you mean UI events your game scene may not have a UI eventsystem.
Ok, I think I pinpointed it, because ok your tip @SpeakUpGames , but I don’t fully understand it yet.
I have the followinf function in my Lobby Player Object (the class extends the Unity NetworkLobbyPlayer):
public override void OnNetworkDestroy ()
{
Debug.Log ("Destroying network object: playerControllerId: " + playerControllerId + ", isLocalPlayer: " + isLocalPlayer);
if (!isLocalPlayer && !readyToBegin && isServer) {
Debug.Log ("Leaving Player is local player.");
UnregisterPlayer();
}
}
an this code in my In Game Player Object (the class extends from NetworkBehaviour):
public override void OnNetworkDestroy ()
{
Debug.Log ("Destroying network object: playerControllerId: " + playerControllerId + ", isLocalPlayer: " + isLocalPlayer);
if (!isLocalPlayer && isServer) {
Debug.Log ("Leaving Player is local player.");
if (NetworkLobbyManager_Custom.UncheckedInstance()) {
NetworkLobbyManager_Custom.Instance ().SendReturnToLobby ();
}
}
}
I think the Problem is, that there is already some kind of calllback, which triggers “SendReturnToLobby” in the Lobby object, which is then called twice and produces the error. I assume this, since the client is sent to the lobby automatically once the server quits, which is intended behaviour, but I never wrote any code for this to happen. So it has to be already implemented either in NetworkLobbyPlayer, which I am extending, or NetworkLobbyManager, which I am using as well.
tl;dr: I commented the line NetworkLobbyManager_Custom.Instance ().SendReturnToLobby (); out. Now it no longer freezes. Thanks for your help, @SpeakUpGames
Just to confirm: when I call NetworkManager.Shutdown() from the OnStopClient() method, the editor also freezes ![]()
I think that Networkmanager.Shutdown() again calls OnStopClient, which would lead to the endless loop. It would help, if we knew, what was going on in the NetworkManager and NetworkLobbyManager classes.
(Completely off the record: you can decompile the Unity.Networking.dll file that comes with Unity using ILSpy. That’ll give you insight into how the NetworkManager & NetworkLobbyManager work in the background exactly. The Unity Networking team is working on making the HLAPI open source soon, so this is definitely a good temporary option.)