Photon "Failed to 'network-remove' GameObject" . . . please help.

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.

Thanks ahead. Any help at all is appreciated.

Here are the full scripts:
Health.cs - https://gist.github.com/mynameisjacobj/6c64c3521a40746ed211
PlayerShooting.cs - https://gist.github.com/mynameisjacobj/70c2faec1a28baba576e
NetworkManager.cs - https://gist.github.com/mynameisjacobj/427e4c9e2e411361f1ee

2 Likes

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 :slight_smile:

5 Likes

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.

5 Likes

Indeed:
Simply checking photonView.isMine when calling PhotonNetwork.Destroy(gameObject) alleviated my problem.
works! Thank you

2 Likes

On the same case, I checked ‘photonView.isMine’ when calling Destroy(gameObject). But it doesn’t work.

1 Like

@mhhk88 Did you managed to find a fix? Iv just encountered this problem and dont know how to get around it…

@mhhk88 , @airbagnr1 : We could use a repro case for this to help you properly. Mail to: developer@photonengine.com please.

        if(Player.GetComponent<PhotonView>().isMine == true && PhotonNetwork.connected == true)
        {
        PhotonNetwork.Destroy(Player.gameObject);
        }

:heavy_check_mark:

__ @tobiass __ Thank you very much !
I also had the problem taht capnjake had,
but now it is solved ! : )

1 Like

Having this issue, not able to fix it through checking if the view is mine… anyone else?

1 Like

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.

Example:

if(PhotonNetwork.IsConnected){
view.RPC(“DestroySelf”, RpcTarget.All);
}

[PunRPC]
public void DestroySelf()
{
Destroy(view.gameObject);
}

1 Like