- Home /
Multiplayer. Destroying player object on Host/Server
Hi all
I have a very rudimentary multiplayer game set up and mostly working. There is however one irritating bug. When the Server player disconnects and then re-starts the server clients then see extra players, as though one or more of them has been duplicated.
I have a hunch that it's connected to the function below, which somewhat surprisingly isn't called when the server disconnects.
Any clues for the clueless ?
void OnPlayerDisconnected (NetworkPlayer player)
{
Debug.Log("Host Destroyed disconnected Player"+player.ipAddress);
Network.RemoveRPCs(player, 0);
Network.DestroyPlayerObjects(player);
PlayerCamera.CameraTarget=transform;
}
Answer by moka_one · Oct 10, 2012 at 05:31 PM
hey! this function above is called only on the server side whenever a client is disconected. If you want a function to be called when the server disconects from the client on the client side then it's OnDisconnectedFromServer
http://docs.unity3d.com/Documentation/ScriptReference/MonoBehaviour.OnDisconnectedFromServer.html
Answer by fujindevil · Oct 10, 2012 at 05:31 PM
when you instantiate the GameObject of the player keep it in a list or array and when the player disconnects delete that object form the list/array.
What i usualy do is:
make a Player object in the player object you have all the player variables.
like networkPlayer, gameObject etc.
then you loop on a disconnect trough all players and check the NP, if it matches destroy the GameObject.
Cheers
Is that not what
Network.DestroyPlayerObjects(player);
is intended to do ?
Your answer
Follow this Question
Related Questions
Network RPC buffer issue 0 Answers
How to apply damage to raycast hitten object's Networkview? 2 Answers
Multiplayer spawning issue - Can't find player 1 Answer
Problem with RPC attribute. 1 Answer
Players Not Showing 0 Answers