Ok, im sure anyone who networks much knows this issue. When a player networkView.RPC’s another player gameObject as a result of shooting them… but the other players end has calculated it is time to die, and destroys itself… due to the slight amount of time it takes for everyone to be updated of this death, another player can still have shot again at that player ( i realise its all micro seconds, but it matters) … and there for , the networkView they try and RPC with is now gone, thus a failed lookup error.
Now i know i can turn off error pause and the game runs through fine … but than it pauses on no other errors whatsoever … and this is not exactly ideal. So my question is , how can i ensure that this error doesnt get thrown.
An example of what i have is a weapon with this in it …
if(Physics.Raycast(ray.origin, ray.direction, hit, range)){
if(hit.collider.tag == "Player"){
Debug.Log(hit.collider.gameObject.networkView.viewID);
try{
hit.collider.gameObject.networkView.RPC("RecievePain", RPCMode.Others, hit.collider.gameObject.networkView.viewID, damage);
//hit.collider.gameObject.SendMessage("RecievePain", damage, SendMessageOptions.DontRequireReceiver);
}
catch(err : System.Exception){
}
}
}
and a playerObject that has this in it …
@RPC function RecievePain(nView : NetworkViewID, damage : int){
//function RecievePain(damage : int){
if(nView.isMine){
stats.health -= damage;
if(stats.health <= 0){
if(weaponController.equippedStatus != EquippedStatus.NONE){
Network.RemoveRPCs(weaponController.currentlyEquipped.gameObject.networkView.viewID);
Network.Destroy(weaponController.currentlyEquipped.gameObject);
weaponController.equippedStatus = EquippedStatus.NONE;
}
//
var playerSpawn : GameObject[] = GameObject.FindGameObjectsWithTag("Respawn");
var random : int = Random.Range(0, playerSpawn.Length);
playerSpawn[random].SendMessage("SpawnPlayer", NetworkAdaptor.clients[0].playerProfile.characterClassIndex, SendMessageOptions.DontRequireReceiver);
//
//Network.RemoveRPCs(gameObject.networkView.viewID);
Network.Destroy(gameObject);
Network.RemoveRPCs(gameObject.networkView.viewID);
}
}
}
Any ideas thanks.
Note , didnt seem to matter what order i tried to kill the RPCs, error still gets thrown.