- Home /
Couldn't invoke RPC to server after Network.Destroy
Hi all, I'm writing a networking game using an authoritative server. My clients send their inputs to the server, the server runs the sim and sends the player positions etc back. Everything is mostly fine, except that I am getting the above mentioned errors immediately after destroying one of my players' objects by calling Network.Destroy on my server, the RPC in question is the one used to send inputs to the server, and is called in the client's Update function.
The update code:
public void Update () {
if (Network.player == owner) {
updateInputs();
if (Network.isClient && Globals.playerState == Globals.PlayerState.ALIVE) {
//send input to server
_networkView.RPC("sendInput", RPCMode.Server, yaw, pitch, roll, throttle, gearState, fire1, fire2);
}
}
}
The code called when the player takes damage:
public void damage(float damage) {
if (Network.isServer) {
health = Mathf.Max(health - damage, 0f);
if (health == 0f) {
_networkView.RPC("die",RPCMode.AllBuffered);
Network.RemoveRPCs(_networkView.viewID);
Network.Destroy(gameObject);
}
}
}
The "die" RPC:
[RPC]
public void die() {
if (Network.player == owner) {
Globals.playerState = Globals.PlayerState.DEAD;
}
<other cosmetic stuff happens here>
}
It would appear that Network.Destroy executes too quickly on the server after the RPC call to "die" is triggered, which cannot quickly enough prevent the client from trying to call "sendInput". However, the networkView has already been destroyed on the server and I get the error:
Could't invoke RPC function 'sendInput' because the networkView 'AllocatedID: X' doesn't exist
Any ideas on how to prevent this?
Wondering if you ever got this solved...as I am facing similar problems. I don't think the explanation you give here is th actual source of the problem. The problem in my opinion is that as you destroyed the player game object on the server, the player game object still exists in the players game instance sending data (until the order to destroy this player is reached from the server). So you are still generating network traffic with no networkview to receive it on the server side. It seems the only way to fix this would be to destroy the gameObject sending the data first and destroying it on the server later. But I need to test this hypothesis.
Your answer
Follow this Question
Related Questions
Networking Error! 0 Answers
OnSerializeNetworkView issus in my 2D game 3 Answers
Overloading RPCs 1 Answer
RPC not sending and not giving an error? 0 Answers
getting error with networkView 0 Answers