The Photon Forum
is Closed Permanently.

After many dedicated years of service, we have made the decision to retire our Forum and switch to read-only: we´ve saved the best to last! Your search result can be found below. Plus, we offer support via these channels:

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).

Write Us
an E-Mail

Feel free to send your question directly to our developers.

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

JohnTube
2019-11-15 13:35:19

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.

Grant
2019-11-15 15:57:23

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.

Grant
2019-11-15 15:57:47

Oh and using the latest Pun 2 version.

Grant
2019-11-15 16:20:55

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.

Grant
2019-11-15 16:24:58

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?!

JohnTube
2019-11-15 17:01:15

Hi @Grant,

Will this screw it up?!
Yes. I just tested this. I will add this to the documentation.

But you should have seen an error in the logs:

PhotonView with ID 1 has no (non-static) method "AddObject" that takes 1 argument(s): String

Grant
2019-11-15 17:07:39

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