Failed to ‘network-remove’ GameObject. Client is neither owner nor masterClient taking over for owner who left: View (0)2001 on Player(Clone)
This is the error I repeatedly get. I’m using quill18creates Multiplayer FPS tutorial as a reference here. This occurs when the client who creates a game attempts to kill another player object. This does not occur (and works as desired) when a player kills another player who spawned BEFORE them.
This is some relevant code from my PlayerShooting script: if (h != null) { PhotonView pv = h.GetComponent (); if (pv == null) { Debug.LogError(“Object has no NetworkView attached”); } else { pv.RPC (“TakeDamage”, PhotonTargets.All, damage); } }
And from my Health script: [PunRPC] public void TakeDamage (float dmg) { currentHealth -= dmg; // Health reduced by damage dealt
if (currentHealth <= 0) { Die (); } }
void Die () { if (GetComponent ().instantiationId == 0) { Destroy (gameObject); } else { if (PhotonNetwork.isMasterClient) { PhotonNetwork.Destroy (this.gameObject); } } }
I’ve spent all morning trying to resolve this and have done various things such as:
Checking if photonView.isMine and destroying it locally, otherwise calling PhotonNetwork.Destroy();
Calling an RPC on my Die method directly to no avail . . .
Every single response to this question from my Google research is something along the lines of “Only the owner can Destroy a GameObject.
The owner is the user who instantiated it. Alternatively, the Master Client has that right, too.”
I get this concept but I have no idea how to implement a fix. In quill18’s tutorial series this simply just works and; in my mind, makes complete sense. I’m just at a loss of what can be done to fix this issue.
While quill18’s tutorial series is excellent and still working in most parts, it might be slightly outdated in a few ways. PUN is being worked on basically all the time, so there might be subtle changes.
It seems like the Master Client was able to destroy anyone’s GameObject (with a PhotonView on it) and now that’s not allowed anymore.
You could change your RPC implementation to make the owner of a PhotonView do the PhotonNetwork.Destroy().
That means that individual owners have to accept the shot and destroy their GOs. It won’t look any different to the players though. Check GetComponent().isMine instead of isMasterClient.
Alternatively, you could pry open PUN and check the source where this error message gets logged. There should be a condition that only allows the controller of a PhotonView, to destroy it. If you add something like " isMasterClient || ", PUN will allow your Master Client to destroy any GO.
This is actually also a valid solution. While PUN can’t allow some things, because they would not work under all conditions, this is a case where the new rules might be too rigid. If your logic makes the Master Client responsible to destroy objects, then it should be OK…
Hope that helps.
By the way: I like how comprehensive your post / question is written
This is a year and a half later but after searching this problem again while working on another project and coming across my question I’ve decided to confirm that @tobiass had the right answer.
Simply checking photonView.isMine when calling PhotonNetwork.Destroy(gameObject) alleviated my problem.
It’s probably a slightly different case. Else the fix would apply.
We could use a repro case for this to help you properly. Mail to: developer@photonengine.com please.
I know this is old, but for me I just create a punRPC void, then have a regular Destroy(gameObject). I tried a bunch of different things but this works for me.