How to check if RPC function exists before calling RPC function

Options
Hi @Tobias

I want to check if RPC function exists before calling the function.

CHECK IF RPCCALL1 EXISTS
IF YES
photonView.RPC("RPCCall1", PhotonTargets.MasterClient, PhotonNetwork.player);
ELSE SKIP

Thanks

Answers

  • sweetmei25
    edited February 2019
    Options
    Hi @JohnTube
    I can't find any solution please help me

    One client calls the RPC function and the target is MasterClient. The MasterClient only has a script contains the RPCCall1 function.
    But the MasterClient exited so error happens.
    Is there any solution to avoid this problem?
  • kriller509
    edited March 2019
    Options

    Hi @JohnTube
    I can't find any solution please help me

    One client calls the RPC function and the target is MasterClient. The MasterClient only has a script contains the RPCCall1 function.
    But the MasterClient exited so error happens.
    Is there any solution to avoid this problem?

    Given that this post has existed for a month I'm afraid you may have already moved on, but allow me to lend advice anyway.

    Rather than checking whether an RPC exists or not, you might want to check if the script exists, so if the RPC exists on ScriptA.cs then do:
    ScriptA test = theObject.GetComponent<ScriptA>();
    if(test != null) {
        // Do the RPC call then
    }
    So basically, since you know Script A has the call, all you have to do is check that the object you're sending the RPC to has the script, and if it does then you know it also has the RPC.
  • sweetmei25
    Options
    :smile: okay
  • sweetmei25
    Options
    I already figured this problem out, but anyway thanks for your kind answer
    Much appreciated! @kriller509 Thanks!