Calling an RPC on a different object/class

Options
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
    JohnTube ✭✭✭✭✭
    Options
    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
    Options
    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
    Options
    Oh and using the latest Pun 2 version.
  • Grant
    Options
    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
    Options
    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
    JohnTube ✭✭✭✭✭
    Options
    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
    Options
    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!