Hello everyone,
I have started recently with Photon.
And I’m facing issue with the RPC API.
I have 2 game objects, both of them have PhotonView attached.
Object 1 is already in scene, Object 2 is spawnned at beginning.
//Object 1 has a Script, and it has the following code snippet
public PhotonView _photonView;
void Start () {
_photonView = this.GetComponent<PhotonView> ();
}
public void PassMessages(){
_photonView.RPC("SendClicked", PhotonTargets.All);
}
[PunRPC]
void SendClicked(){
print ("Message from same component ");
}
//Object 2 has a different Script, and has the following code snippet
[PunRPC]
void SendClicked(){
print ("Message from RPC: ");
}
The problem is, the SendClicked method from Object 1 is called but it dosen’t call from object 2.
Please help me to solve this issue.
~Thanks
RPCs are always called on the same networked object, not on all scripts in the scene.
It’s a broadcast for the network, not for “all objects that happen to have the method”.
In your case, you call the RPC on an empty object, which is not actually the target for the message. If you check, script 1 on all clients in the room should execute the RPC.
You can solve the problem in two ways:
a) Make your player object (with script 2) known to your input UI. When you instantiate your character, you can also store it as variable (e.g. in the chat input scripts). Your UI button will have to call RPC() on that object.
You can also grab the PhotonView of your own, instantiated game object and store it for use by the UI.
b) You can continue to call the RPC on a unrelated game object. Then, you will have to find the sender’s game object, so you can show the text.
The sender of an RPC is available for you, if you simply add a parameter PhotonMessageInfo to the RPC method.
Described here:
http://forum.unity3d.com/threads/how-to-photon-networking-send-gameobjects-transforms-and-other-through-the-network.343973/#post-2224982
I would do a).
Hey tobiass,
I am supposed to create a virtual chat room.
Where other people can join and chat.
I’m using RPC to send message to my client, which is spawned.
But the RPC method in player object is not called at all.
It just calls the local RPC method, which is in the same script, from where i’m calling.
I think Unity has updated the networking component in 5.1, and still photon has
not updated the plugin. So, The photon plugin is not compatible with 5.1.
May be it will work on 5.0.
I’ll try it.
Anyways Thanks you for responding.