Calling an RPC on a different object/class
The whole answer can be found below.
Try Our
Documentation
Please check if you can find an answer in our extensive documentation on PUN.
Join Us
on Discord
Meet and talk to our staff and the entire Photon-Community via Discord.
Read More on
Stack Overflow
Find more information on Stack Overflow (for Circle members only).
Calling an RPC on a different object/class
Grant
2019-11-14 23:15:27
Hi, I'm trying to call an RPC on a scene object, the scene's game controller, from a UI object but it doesn't seem to be received on any object. Is this not possible? Calling this from a UI class/object to send to the Master Client:
Controller.instance.photonView.RPC("AddObject", RpcTarget.MasterClient, name);
But nothing seems to happen. Thoughts?
Comments
Hi @Grant,
Thank you for choosing Photon!
What PUN version are you using?
Does the same GameObject as the PhotonView have a MonoBehaviour (or class that extends it) that implements the "AddObject" RPC method?
Does it have the same signature?
Does it have the "PunRPC" attribute?
Do you see "AddObject" in the PhotonServerSettings' "RPCs List"?
What do you see in the logs? any warning or error?
Read about "RPCs Considerations" here.
Hi John, yep read all the RPC details. To answer your questions, Yes the GO has a PV component on it (to run RPCs it doesn't need to observe the script, right?) and it has the AddObject method with the right signature ((the Controller object I'm referencing from the UI script but not he UI script itself). It has the [PunRPC] attribute. Wait, do we have to register the RPC list? I didn't see that anywhere. Can you point me to the details on that?? Maybe that's it.
Oh and using the latest Pun 2 version.
OK, I actually found the PhotonSettings file in resources. And it does indeed appear that it registered my AddObject RPC method. It is listed under the RPC section. So I'm at a loss why this isn't getting called. No errors given either. Just never calls.
Hold on, regarding the signature. The AddObject via RPC is calling AddObject(string) but the signature is actually AddObject(string, int = -1, float = 0) with the last two parameters having default values. Will this screw it up?!
Hi @Grant,
But you should have seen an error in the logs:
Ha ha. Yep that was it! So I just passed in parameters to match and now it works. Kind of a bummer if there are default parameters but in this case not a big deal. Adding to the documentation would be great for noobs like me to Photon. Didn't see an error but could have missed it. Have a lot of reporting going on. Thanks!
Back to top