Search Unity

Bug [PHOTON] Can't destroy network object that created by other player even if MasterClient

Discussion in 'Multiplayer' started by darceyo, Jan 30, 2024.

  1. darceyo

    darceyo

    Joined:
    Jan 10, 2024
    Posts:
    29
    I'm making object sync in my game, and noticed that i can't destroy object that was created by other player using PhotonNetwork.Destroy(object); even if MasterClient

    I'm sharing my code and hope that Photon staff will help me to solve it.
    Code (CSharp):
    1.                 if (photonView.IsMine && PhotonNetwork.InRoom)
    2.                 {
    3.                     var objectView = collider.GetComponent<PhotonView>();
    4.                     if (objectView.Owner == photonView.Owner)
    5.                     {
    6.                         PhotonNetwork.Destroy(object);
    7.                     }
    8.                     else
    9.                     {
    10.                         photonView.RPC("MP_Destroy", RpcTarget.MasterClient, photonView.ViewID, objectView.ViewID);
    11.                     }
    12.                 }
    RPC Code:
    Code (CSharp):
    1.     [PunRPC]
    2.     public void MP_Destroy(int player_id, int viewID)
    3.     {
    4.         if (PhotonNetwork.IsMasterClient)
    5.         {
    6.             PhotonView objectPhotonView = PhotonView.Find(viewID);
    7.             print("MP_Destroy You are host, object destroyed : " + viewID);
    8.             GameObject obj = objectPhotonView.gameObject;
    9.             if (obj != null)
    10.             {
    11.                 PhotonNetwork.Destroy(obj);
    12.             }
    13.         }
    14.  
    15.     }
    Error:
    Failed to 'network-remove' GameObject. Client is neither owner nor MasterClient taking over for owner who left: View 2003 on "object"

    Other Info:
    • Master ID: 1001
    • Client ID that sent RPC: 1001 (master)
    • Object ID: 2003
    • Object owner ID: 2001
    • Owner is still on the scene (he is not left)

    MasterClient is received the RPC call, but output the Error above.
    Probably i'm just confused, but it should work this way!
    What i'm doing wrong here?
     
    Last edited: Jan 30, 2024
  2. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,066
    I am basically as puzzled as you are. Why is object 2003 involved here? Is that the "collider"?
    Maybe that is where things are mixed up.
    You want to call the RPC on the networked object you target (and which is the one that should get destroyed). That's enough to actually "target" it, because RPCs are executing the script on the object related to the PhotonView.
     
    Last edited: Jan 30, 2024
  3. darceyo

    darceyo

    Joined:
    Jan 10, 2024
    Posts:
    29
    Yes, it's an collider. But what i want to say, that this collider was created by other player (2001).
    The idea is that each player can create some objects, and any other player can interact with these objects.

    So what i have tried in first post is:
    1. player with ID 2001 created an object that have PhotonView = 2003 (because it's not first created object by this player)
    2. other player, which is master server in this case, trying to send RPC to MasterServer (literally to himself).
    3. error.