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.
if (photonView.IsMine && PhotonNetwork.InRoom)
{
var objectView = collider.GetComponent<PhotonView>();
if (objectView.Owner == photonView.Owner)
{
PhotonNetwork.Destroy(object);
}
else
{
photonView.RPC("MP_Destroy", RpcTarget.MasterClient, photonView.ViewID, objectView.ViewID);
}
}
RPC Code:
[PunRPC]
public void MP_Destroy(int player_id, int viewID)
{
if (PhotonNetwork.IsMasterClient)
{
PhotonView objectPhotonView = PhotonView.Find(viewID);
print("MP_Destroy You are host, object destroyed : " + viewID);
GameObject obj = objectPhotonView.gameObject;
if (obj != null)
{
PhotonNetwork.Destroy(obj);
}
}
}
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?