- Home /
RPC error on player disconnected
Whenever a player disconnects the Server/Client which has an RPC in the update function will send that function to the disconnected player 1 time. How can I prevent this?
function Update() {
if (Network.isServer || Network.isClient) {
networkView.RPC("Sync", RPCMode.Others, transform.position, transform.rotation);//This will be sent to the player once after they have disconnected.
}
}
Answer by shockelite · Feb 01, 2015 at 09:41 AM
If the player disconnects it wont be able to send anything to the server or other clients via RPC. You should probably use these functions "OnPlayerDisconnected", and "OnDisconnectedFromServer". Hopefully I'm understanding your question correctly.
/// <summary>
/// Raises the player disconnected event.
/// CALLED ON SERVER
/// </summary>
void OnPlayerDisconnected(NetworkPlayer _networkPlayer) {
Network.RemoveRPCs(_networkPlayer);
Network.DestroyPlayerObjects(_networkPlayer);
Debug.Log("Removed player ("+ _networkPlayer.ipAddress +") RPC's");
}
/// <summary>
/// Raises the disconnected from server event.
/// Called on client during disconnection from server, but also on the server when the connection has disconnected.
/// CALLED ON CLIENT
/// </summary>
/// <param name="info">Info.</param>
void OnDisconnectedFromServer(NetworkDisconnection info){
switch(info){
case NetworkDisconnection.Disconnected:
Debug.Log ("Disconnected");
break;
case NetworkDisconnection.LostConnection:
Debug.Log ("LostConnection");
break;
}
}
Your answer
Follow this Question
Related Questions
RPC to specific clients Problem: networkView.RPC("SetPosRot", item._networkPlayer, pos, rot); 1 Answer
Need Help with function parameters and RPC parameters! 1 Answer
Is an RPC call asynchronous? 2 Answers
Networking between projects: how to send ViewIDs? 1 Answer
Passing variables back and forth in client server environment using RPC 1 Answer