Search Unity

Can't restart a network game.

Discussion in 'Multiplayer' started by SpaceMidget75, Feb 11, 2016.

  1. SpaceMidget75

    SpaceMidget75

    Joined:
    Feb 7, 2014
    Posts:
    21
    I appear to have the exact same issue listed here. It was suggested that it was fixed last year but I'm using the latest version.

    I'm using NetworkManager and NetworkManagerHUD. Have a lobby scene, a game scene set and a player prefab set in the manager. The only thing I'm doing differently is I'm manually spawning the players using this code (creating a maximum of 2 players and then setting the game to ready) so I don't have autocreateplayer ticked:

    Code (CSharp):
    1.     public override void OnServerAddPlayer(NetworkConnection conn, short playerControllerId)
    2.     {
    3.         GameManagerScript gameManagerScript = GameObject.Find("GameManager").GetComponent<GameManagerScript>();
    4.  
    5.         Vector3 pos = new Vector3(-8, 0, 0);
    6.         Quaternion rot = Quaternion.Euler(new Vector3(0, 0, -90));
    7.         if (gameManagerScript.Players.Count == 1)
    8.         {
    9.             pos = new Vector3(8, 0, 0);
    10.             rot = Quaternion.Euler(new Vector3(0, 0, 90));
    11.         }
    12.         GameObject player = (GameObject)Instantiate(playerPrefab, pos, rot);
    13.         player.name = "Player1";
    14.         ShipScript shipScript = player.GetComponent<ShipScript>();
    15.         shipScript.Player = 1;
    16.         if (gameManagerScript.Players.Count == 1)
    17.         {
    18.             player.name = "Player2";
    19.             shipScript.Player = 2;
    20.             gameManagerScript.Active = true;
    21.         }
    22.  
    23.         gameManagerScript.Players.Add(shipScript);
    24.  
    25.         NetworkServer.AddPlayerForConnection(conn, player, playerControllerId);      
    26.     }
    Everything works, but if I end the host or a client leaves, there's nothing I can do to get a new game to work properly. Even restarting the client application doesn't allow them to reconnect. Stopping Host and Starting again also doesn't work.

    I have this appearing in the console: "empty player list given to networkserver.destroy() nothing to do" and even more weirdly the HUD seems to corrupt and appears to be duplicated and overlaying itself.

    Is there something that needs to be run to destroy connections if I'm manually creating player spawns?
     
    Deleted User likes this.
  2. Xergz

    Xergz

    Joined:
    Aug 23, 2016
    Posts:
    3
    I have a very similar issue using Unity 5.5.1f1. Whenever a client leaves, they can't connect back and I get that error message. Is this a bug or is there a solution? I can supply a repro project if need be.
     
    Last edited: Mar 7, 2017