Im having troubles deleting scene objects. At least I think that is the problem.

Options
Hello,

I use a lot of scene objects in my game, and these are the errors/warning I get all the time:

Ev Destroy Failed. Could not find PhotonView with InstantiationID XY. Sent by actorNr: XY

Failed to 'network-remove' GameObject. Client is neither owner nor masterClient taking over for owner who left: View...

Had to lookup view that wasn't in photonViewList: View (0)867 on RitualBoneDetached(Clone)

Received RPC "changeOpenClose" for viewID 125 but this PhotonView does not exist! Was remote PV. Remote called. By: 4 Maybe GO was destroyed but RPC not cleaned up.

Received RPC "destroyNowRPC" for viewID 837 but this PhotonView does not exist! Was remote PV. Remote called. By: 5 Maybe GO was destroyed but RPC not cleaned up.

Often the game crashes from result of those(or crashes are connected to the same cause). Now, I am destroying scene objects by calling this RPC:

 [PunRPC]
    public void destroyNowRPC()
    {
        if (PhotonNetwork.isMasterClient || photonView.isMine)
            PhotonNetwork.Destroy(this.gameObject);
    }
I am wondering what am I doing wrong and how to prevent it. I searched through the forums but couldn't find a solid answer.

I am using PhotonNetwork.SetMasterClient to switch master client in a regular time delay. That is to prevent possible cheating/controlling the game from the side of a single player that is the admin. Could that be the cause of some of it?

Thank you for your help in advance.

Comments

  • I had the same issue and Im not advanced with Photon networking but my solution was to just use destroy instead of photon network destroy. So leave [PunRPC] destroyNowRPC() how it is and remove if(master or view is mine) and just call Destory(this.gameObject);. This worked for my situation. Hope this helps you!
  • Fearem
    Options
    Hmm, but I don't think that actually removes the object from the server (if it is stored there, not sure?). Can someone confirm that this solution would work?
  • PhotonNetwork.Destroy will remove the buffered Instantiation call from the server and will remove this certain object on all clients, too. It can only be used by the Owner of the object or the MasterClient if the object either is a Scene Object or the ownership of the object has been transferred to the MasterClient.

    If you want to automatically remove player objects (not Scene Objects), check if PhotonNetwork.autoCleanUpPlayerObjects or RoomOptions.CleanupCacheOnLeave is enabled.

    Objects of players can be destroyed by using PhotonNetwork.DestroyPlayerObjects, too. In this case a client can again only destroy his own objects. An exception in this case is the MasterClient, who can destroy anyone's objects.
  • Fearem
    Options
    I ended up taking over the scene object and then destroying it. Seems to be doing the trick.