Manual Destroying Script

Options
I have trouble with this error:

UnAllocateViewID() should be called after the PhotonView was destroyed (GameObject.Destroy()). ViewID: 1004 still found in: View (0)1004 on SomeGameObject(Clone)
public void NetDestroy( GameObject obj )
{
        //PhotonNetwork.Destroy( obj.GetPhotonView() );
        photonView.RPC( "RPCDestroy", PhotonTargets.AllBuffered, obj.GetPhotonView().viewID );
}
[PunRPC] public void RPCDestroy( int toDestroyID )
{
        GameObject gObjToDestroy = PhotonView.Find( toDestroyID ).gameObject;
        
        // I want to do some logic around destroyed object, eg.:
        // gObjToDestroy.GetComponent<INetDestroyListner>().OnDestroy();
        // if( PhotonNetwork.isMasterClient )
        //    gObjToDestroy.GetComponent<INetDestroyListner>().OnMasterDestroy();
        // Nowadays it's empty.

        Destroy( gObjToDestroy );

        if( PhotonNetwork.isMasterClient )
            PhotonNetwork.UnAllocateViewID( toDestroyID );
}
What am I doing wrong?

Please help! :s

Comments

  • MasterMati
    Options
    The problem was just to DestroyImmediate not to Destroy. GameObject was still on scene when trying to unallocate ID :p