Killing player 1 (Server) closes / kills all players

Hi, when I start a game I have a scene loaded up with no players in it, each players screen shows a GUI menu of two buttons

  • Start Server
  • Refresh Hosts

If I then press button 1 it runs

function startServer(){
	Network.InitializeServer(4,25001, !Network.HavePublicAddress);
	MasterServer.RegisterHost(gameName, "Lab Multiplayer", "..");
}

then

function OnServerInitialized(){
	spawnPlayer();
}

that runs my spawnPlayer() function that spawns my player becoming the server?

I then connect other devices and pressing button 2 they join the game as clients, all is well if any players kill other players up to 3 time as I have them to re spawn 3 times, I re spawn them by deactivating the gameObject for a X amount of time then moving it to a randomly chosen spawn poin reactivating the gameObject.

My problem is when killed the fourth time I use

	networkView.RPC ("networkDisconect", RPCMode.Others);
	Network.RemoveRPCs(Network.player);
	Network.Destroy(player);

@RPC
function networkDisconect(){
	Network.Disconnect();
}

and if its a client it works and goes back to see the GUI menu of 2 buttons, but If its player 1(server) everyone goes back the the GUI menu, do I have to start the server first as the level then join all players as clients or do I need to use different code to kill player 1?

Thanks.

I believe the issue is the “Network.Disconnect()” line - if the server disconnects then all the clients will be automatically disconnected as well.

The player 1 actually IS the server. There is no fallback to another host if that player leaves, the machine gets shut down or anything similar.
Unity’s networking is not “peer to peer”. All clients connect to one special host and communicate through that. If that’s going down, so are the connections.
If you want to keep the game alive you have to make sure the central server is staying available.