Photon/Network - Killing A Client Enemy Unit

I’ve already asked this on the Photon forum, but I suppose this is also a Unity Network question too, so apologies for double posting in a different forum.

I’m wondering what the best approach is for my unit to attack, send damage, and kill across a network (photon specifically). 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:

function RecievingDamage(){

	currentHealth -= 5;

Then, to kill the unit, I do this locally:

if(currentHealth <= 0 && !isDead){
	photonView.RPC("UnitDead", PhotonTargets.All);

function UnitDead(){

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


		//remove selves from UnitManager

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?

i’ve achieved this, first i photon.instantiate my enemies on create room, (im new to photon and this was only way i knew how to go about it there is probably better methods) then set a boolean, have to ask though did u try, PhotonNetwork.Destroy(photonView.gameObject); ? try setting up a second boolean, send its value to the owners script to set ur initial bool isDead true then add that boolean as a parameter inside the is mine section, i would have submitted example code but my pc isn’t letting me so if u still need help email me,

I haven’t done it yet but I’ve been planning a PhotonNetwork implementation for a few days now. My system will involve casting spells to deal damage. The system is slightly different then yours and rellys on the master client to kill enemies and synchronize it across each cient.

Step 1. Cast spell using RPC. This will create the same spell on every client.
Step 2. Hit enemy, and check if I am the master client. I apply damages locally but dont destroy gameobjects.
Step 3. If the enemy’s health is <1 && I am master client I use PhotonNetwork.Destroy to remove the enemy.

Theoretically this will eliminate the lost RPC calls that happen when you call [RPC] DamageEnemy(). Instead of sending DAMAGE across a server and discovering that the enemy has been destroyed already on that client, we only send ATTACK data over the server and then let the Master Client decide if the enemy should be removed or not. The enemies can still be damaged locally by the attacks but only the Master decides when to remove them over the network.

I haven’t implemented this yet but I think it will work. Every client should have the same gameobjects in place until the buffered PhotonView.Destroy() method removes them.

Sorry if the solution came too late to help you (I know its been a couple of months since you posted) but hopefully this solution works for others.


Maybe try doing


That's what seems to work for me.