Killing A Client Enemy Unit

Hello,

I'm wondering what the best approach is for my unit to attack, send damage, and kill across a network. Currently, everything works just as expected, but I occasionally get warning about Receiving RPCs for PhotonViews that don't exist, possibly because its been destroyed/killed. I just want to know if I'm doing it correctly, to prevent further errors/issues down the line.
"Received RPC "UnitDead" for viewID 1004 but this PhotonView does not exist! View was/is ours. Remote called".
"Received RPC "RecievingDamage" for viewID 1004 but this PhotonView does not exist! View was/is ours. Remote called".

Okay, so what happens is that my player locally fires a raycast to an enemy unit, and sends 'RecievingDamge' to the target via RPC:
if(hit.collider.gameObject.tag == "Unit"){
	var targetID = hit.collider.gameObject.GetComponent(PhotonView);
	targetID.photonView.RPC("RecievingDamage", PhotonTargets.All);
}

Then, on my enemy unit, I have the receiver:
@RPC
function RecievingDamage(){

	currentHealth -= 5;
	Health.system.SetActive(true);
}

Then, to kill the unit, I do this locally:
if(currentHealth <= 0 && !isDead){
	photonView.RPC("UnitDead", PhotonTargets.All);
}

@RPC
function UnitDead(){

	isDead = true;
	Instantiate(explosion, transform.position, transform.rotation);

	if(photonView.isMine){

		//remove selves from UnitManager
		GC.UM.RemoveUnit(transform);
		PhotonNetwork.Destroy(photonView);
	}
	//Destroy(gameObject);
}

I sure would appreciate any feedback, am I doing this correctly? I think my main issue here really is the 'PhotonNetwork.Destroy(photonView);', maybe I should destroy the unit locally on every client?
Thanks

Comments

  • Make sure that RecievingDamage and UnitDead RPC's fired only once per event (from attacker or owner client for instance).
    If it's true then everything is ok with your code. You get warnings because of delays in synchronization. Sometimes hitting client does not know yet that other unit just destroyed.
Sign In or Register to comment.