Search Unity

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

Discussion in 'Connected Games' started by capnjake, Dec 3, 2015.

  1. capnjake

    capnjake

    Joined:
    Nov 12, 2013
    Posts:
    51
    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<PhotonView> ();
    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<PhotonView> ().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
     
    Songersoft likes this.
  2. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    2,241
    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<PhotonView>().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 :)
     
    Songersoft likes this.
  3. capnjake

    capnjake

    Joined:
    Nov 12, 2013
    Posts:
    51
    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.
     
    tobiass likes this.
  4. sashahush

    sashahush

    Joined:
    Sep 5, 2012
    Posts:
    75
    Indeed:
    Simply checking `photonView.isMine` when calling `PhotonNetwork.Destroy(gameObject)` alleviated my problem.
    works! Thank you
     
    tobiass likes this.
  5. mhhk88

    mhhk88

    Joined:
    Sep 12, 2013
    Posts:
    3
    On the same case, I checked 'photonView.isMine' when calling Destroy(gameObject). But it doesn't work.
     
    LoudCorp-Games likes this.
  6. airbagnr1

    airbagnr1

    Joined:
    Nov 16, 2015
    Posts:
    1
    @mhhk88 Did you managed to find a fix? Iv just encountered this problem and dont know how to get around it...
     
  7. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    2,241
  8. DRIVER1ksa

    DRIVER1ksa

    Joined:
    May 29, 2015
    Posts:
    27
    Code (CSharp):
    1.         if(Player.GetComponent<PhotonView>().isMine == true && PhotonNetwork.connected == true)
    2.         {
    3.         PhotonNetwork.Destroy(Player.gameObject);
    4.         }
     
  9. Omane

    Omane

    Joined:
    Mar 30, 2018
    Posts:
    1
    @tobiass Thank you very much !
    I also had the problem taht capnjake had,
    but now it is solved ! : )