- Home /
Send gameobject through photon RPC
Why i have a error here ? i was very good on my game until i got stuck on this error.. i can send bool, int, string but i cant send gameobjects...
pObj.GetComponent<PhotonView>().RPC ("RPCtest", PhotonTargets.All, this.gameObject);
Nope, you cannot send gameObjects. You can send a string of the gameObject name or tag, or send the gameObject Photon ID (integer).
This is the Unity Scripting reference for RPCs, though the Photon parameters are the same : https://docs.unity3d.com/Documentation/Components/net-RPCDetails.html
Answer by tobiass · May 09, 2014 at 03:41 PM
You can't send GameObjects. Even in a networked game, each client can have a different count of GameObjects and that makes it impossible to reference one by name or hierarchy or whateber.
This is why we use the PhotonView component. This is synchronized across all clients in a room. You can use the PhotonView.viewID as reference and find it via PhotonNetwork. If you call an RPC on a PhotonView, PUN will execute the named method only on scripts of that GameObject! This means, there is a good chance you don't have to send a GameObject OR viewID anymore.
Be careful, even with viewIDs, some client maybe destroyed some GameObject while your RPC traveled through the net. In some cases, you won't find the PhotonView anymore.
which method to use to find the game object once I have photon view Id?