- Home /
LobbyManager / NetworkManager doesn't reset properly
I'm having trouble making the LobbyManager (which inherits from NetworkManager) work again after a successful online match. There is no documentation at all on how to do this, especially in regards to the LobbyManager. I have tried many different ways of resetting it, including disconnecting all connections, calling StopClient and StopServer, calling NetworkServer.Shutdown, NetworkServer.Reset, and also many of these or all of these at the same time.
The server restarts normally, and apparently the local client is able to connect to it. However, whenever a remote client connects to the reset server, it jumps to the playScene directly, as if all clients had signaled they were ready, or as if it still thought the match was not finished. Since I can't find any documentation on this, I simply cannot know if I'm doing something wrong, or if this is a Unity bug. So I guess my question is: What should we do to properly reset the LobbyManager?
Hi, did you ever find a solution for this? I'm creating a match -> exiting -> and then can't create a new one ("A connection has already been set as ready. There can only be one.").
Answer by bliu886 · Jan 24, 2018 at 05:53 PM
For anyone still looking for an answer, this seems to happen because the server isn't being fully shutdown and connections are still open. In Unity version 2017.2.0f3, to fully close all the server connections and ports in the LobbyManager is calling Shutdown(). Here is some sample code:
public override void OnServerDisconnect(NetworkConnection conn)
{
Debug.Log("Client disconnected: " + conn.lastError);
// Removes the player game object from the world.
NetworkServer.DestroyPlayersForConnection(conn);
// Stop listening on the port, but port is still open and world state is kept.
int id = PlayerByConnection(conn.connectionId);
playerList.Remove(playerList[id]);
// The last person in the game left.
if (playerList.Count < 1)
{
// Forces the server to shutdown.
Shutdown();
// Reset internal state of the server and start the server again.
Start();
}
}
Answer by joaokan · Nov 06, 2018 at 10:07 AM
A little late to the party, but I've had this problem for a while and finally got to fix it today. Turns out that the NetworkManager has a static variable called networkSceneName which is not reset when the server shuts down. So the next time the server starts, every client that connects will be sent a message to change to the active network scene of the previous game. Resetting this variable to "" after calling Shutdown() solved the issue for me.
Answer by Kurius · Feb 27, 2019 at 11:18 PM
I know this is an old thread but it's a top Google search result. What finally solved it for me was to have the client locate the host player GameObject, then call Command and ClientRpc methods via the Host in order to simulate the Host leaving the game and thus ending the game for everybody. This was the only full proof method for the Client to be able to successfully leave the current networked multiplayer game (but not quit the app), then join a new networked game. I know this is not an ideal solution, but it works 100% of the time.
Answer by transporter_gate_studios · Mar 06, 2018 at 08:11 PM
can you share some code? I'm having the same problem. I'd like to be able to have a user exit and host a new server without having to restart the application