Search Unity

[SOLVED] Duplicating Players After Multiple Logins

Discussion in 'Multiplayer' started by alexander_q, Sep 15, 2014.

  1. alexander_q

    alexander_q

    Joined:
    Feb 7, 2014
    Posts:
    32
    After each login to my server, each client instantiates an extra prefab for itself, and causes each previous client to spawn an extra one, ad infinitum.



    My guess is that this has something to do with buffered RPC calls - each new client calls its own Network.Instantiate, and also receives each previous Network.Instantiate. I don't understand how this causes previous clients to receive new instantiations that they can then control (each window in the image above controls four clients simultaneously). This accrual of prefabs occurs even if previous clients have logged out before new ones appear.

    I don't understand why this should be the case, because in the server I do:

    Code (CSharp):
    1. void OnPlayerDisconnected(NetworkPlayer networkPlayer){
    2.         Network.RemoveRPCs(networkPlayer);
    3.         Network.DestroyPlayerObjects(networkPlayer);
    4.     }
    ... And for good measure I've started having the client do:

    Code (CSharp):
    1.     void Update(){
    2.         if (Input.GetKeyDown(KeyCode.Escape) && connected){
    3.             Network.RemoveRPCs(localPlayer.networkView.viewID);
    4.             Network.Disconnect();
    5.             Application.Quit();
    6.         }  
    7.     }
    What have I missed?

    The full networkManager code is here and the code that spawns players upon entering Level 1 is here
     
  2. alexander_q

    alexander_q

    Joined:
    Feb 7, 2014
    Posts:
    32
    Solved: The problem was here:

    Code (CSharp):
    1. void OnPlayerConnected(NetworkPlayer player){
    2.         print ("Playe connected. Sending seed: "+seed.ToString());
    3.         networkView.RPC("GetSeed",RPCMode.OthersBuffered,new object[]{seed});
    4.     }
    Because of "OthersBuffered", existing players were getting this RPC and re-running their spawn player scripts. I've since altered this to target the specific player connecting.
     
unityunity