Search Unity

A connection has already been set as ready. There can be only one

Discussion in 'Multiplayer' started by cephalo2, Dec 7, 2017.

  1. cephalo2

    cephalo2

    Joined:
    Feb 25, 2016
    Posts:
    263
    So I'm using the NetworkLobby package. My game is a two player game, but the players have no avatar in the game world, it's more like chess. The concept of a 'player' makes it very hard to understand for me because it doesn't apply to my game like it might for other games. I'm using empty 'player' objects because I just don't have any need for them.

    Anyway, when I start my game, it works fine. Then when I exit back the main menu, and try to start a second game, I get the error in the title. It's like I didn't clean up properly when exiting. My code for exiting is like so:

    Code (CSharp):
    1.     public void ReturnToMainMenu()
    2.     {
    3.         print("Stopping Host");
    4.      
    5.         MyNetworkManager.Instance.StopHost();
    6.         MyNetworkManager.Instance.StopClient();
    7. //        MyNetworkManager.Instance.client.Disconnect();
    8.         //SceneManager.LoadScene(MyNetworkManager.Instance.lobbyScene);
    9.     }
    10.  
    I'm stopping the host and also the client for good measure, probably don't need both but the result is the same even I just use StopHost(). Is there something else I need to do to clean up? The comments are old code reflecting my previous failed understanding of how to stop a game.

    When I start a game the second time, I notice that the lobby creates two players instead of one. I have this print statement in my MyLobbyPlayer object.
    Code (CSharp):
    1.     public override void OnClientEnterLobby()
    2.     {
    3.         base.OnClientEnterLobby();
    4.         print("player entering lobby.");
    5.     }
    6.  
    This statement appears twice in my log on the second playthrough after returning to the main menu. Other threads on this issue aren't the same as my issue, because people were getting this on the first run of their game, it almost seemed to be a bug that existed then inside NetworkLobby. But my issue is different.

    I will need a lobby, but I don't need 'players' in my game world. I can't figure out how to handle this in a clean way.
     
  2. cephalo2

    cephalo2

    Joined:
    Feb 25, 2016
    Posts:
    263
    Ok, I finally got around to solving this issue. The problem was that I was deriving my own network manager from NetworkLobbyManager and I was using my own DontDestroyOnLoad(gameObject) instead of the check box inherited from NetworkLobbyManager. Apparantly there's stuff under the hood that goes wrong if you don't use the check box.

    Also, I learned that you can't put your RegisterHandler calls in the Start() method! You need to re-register them when the server disconnects. I put them in the OnServerReady function instead and it appears to be working. I can now go back and forth from lobby scene to play scene.