MasterClient can't destroy the object

As far as I know, the master client can destroy the game object even it's not owned, but when the master attempts to destroy it, I got this error message:

Failed to 'network-remove' GameObject. Client is neither owner nor MasterClient taking over for owner who left: View 2004 on ThrowingExplosiveGrenade(Clone)

So to check the code actually invoked from the master, I simply added two print methods to check isMine and IsMasterClient:
print(photonView.IsMine);
print(PhotonNetwork.IsMasterClient);

PhotonNetwork.Destroy(gameObject);

If the master created and tries to delete it:
print(photonView.IsMine); -> true
print(PhotonNetwork.IsMasterClient); -> true

If the other player created but the master tries to delete it:
print(photonView.IsMine); -> false
print(PhotonNetwork.IsMasterClient); -> true

So the code is always invoked from the master client, not the others.

I don't know how the PUN works internally, but the code where the error was caught doesn't seem to have an additional check the player who tries to delete it is a master, but only checks it's owned or not.

Here's the code directly copy and pasted from PhotonNetworkPart.cs, line 794:
PhotonView viewZero = foundPVs[0];

// Don't remove GOs that are owned by others (unless this is the master and the remote player left)
if (!localOnly)
{
    //Debug.LogWarning("Destroy " + instantiationId + " creator " + creatorId, go);
    if (!viewZero.IsMine)
    {
        Debug.LogError("Failed to 'network-remove' GameObject. Client is neither owner nor MasterClient taking over for owner who left: " + viewZero);
        foundPVs.Clear();   // as foundPVs is re-used, clean it to avoid lingering references
        return;
    }
}

Have I misunderstood something or just PUN implemented it wrong? Using Unity 2019.1.0f2 and PUN 2 4.1.6.3

Comments

  • Hello.
  • JohnTube
    JohnTube ✭✭✭✭✭
    Hi @modernator,

    By design:
    • Regular player objects can only be destroyed by their owner OR their controller (current Master Client) in case owner is inactive.
    • Master Client can delete room objects OR regular player objects that he is controlling (because owner is inactive).

    If this is not the behaviour you see:

    Make sure you are destroying the expected GameObject, e.g.:
    PhotonNetwork.Destroy(photonView.gameObject);
    

    Please update to latest PUN 2.
    By the way, 4.1.6.3 is the version of Photon Realtime and Photon Unity library included and used by PUN 2.

    PUN 2 latest version is 2.34.1.
  • Thanks for the explanations, but still have some not yet understand.
    JohnTube wrote: »
    Regular player objects can only be destroyed by their owner OR their controller (current Master Client) in case owner is inactive.

    Are "regular player objects" indicates that the objects created by other players, using PhotonNetwork.Instantiate?

    And what is the controller, and you said controller is "current Master Client", so is this implies that the master client can destroy what it called "regular player objects"?
    JohnTube wrote: »
    Make sure you are destroying the expected GameObject, e.g.:
    PhotonNetwork.Destroy(photonView.gameObject);
    

    Yes, I am destroying the expected GameObject, already checked several times.

    So I guess that the master can destroy the objects created by other players, but IDK, I got an error it can't be done. I'm going to update PUN2 to the latest version right now, hope it is fixed.
  • JohnTube wrote: »
    Hi @modernator,
    PUN 2 latest version is 2.34.1.

    Well, I just checked that I'm already using the latest version.

  • Still waiting for an answer.

    Just for now, temporarily solved by force to create an object through the master client, which means that if the other player wants to create an object, sending RPC to the master client to instantiate instead.
  • We only allow PhotonNetwork.Destroy(view), on the client that controls the PhotonView. It's problematic to destroy an object someone else still writes updates for (in parallel), so we don't allow this.

    The controller is the client that sends the updates for this view and on this client only IsMine is true.
    Usually this is the creator of an object. If the creator leaves, the Master Client becomes the controller of an object (and thus becomes the client which can destroy the object). By default, however, objects created by players will be destroyed anyways when they leave.

    I have to admit, I didn't read all of the discussion. Hope this helps, else please ask about what's still unclear.