PhotonNetwork.Destroy() vs RPC arrival order

Options
I've searched around and haven't been able to find a good answer.

In my app, I need to destroy a previously network instantiated gameobject. I can do this through PhotonNetwork.Destroy(). My problem is that due to the nature of my program I have a render-to-texture camera that is dynamically parented to these same objects. It is important that the camera be detached from the gameobject prior to that game object being destroyed. (Each user may have their unique non-networked render-to-texture camera attached to a completely different object while in play) I have tried different implementations. The most elegant I thought was to put this code in OnDisable() on the object that was being destroyed but Unity logs an error saying that you cannot change the hierarchy on objects being disabled.

So my next best solution is to fire an RPC prior to the object's destruction and remove the camera from the object if it is attached to the dying object.

So in my code it basically goes:
photonView.RPC("CheckToDetachCamera", PhotonTargets.All);
PhotonNetwork.Destroy(object);

Obviously if the Destroy commands arrives prior to the RPC then I'm back to the core problem- the child camera will be destroyed as well. Is there any guarantee that the RPC will always arrive before the Destroy command?

Comments

  • vadim
    Options
    Both RPC and Destroy send reliable Photon events which are always delivered on all clients in same order as they are sent. So RPC always arrives before Destroy in your case.