How does PUN RPC works, with same function name, different parameters?

Options
I have a question regarding PUN's RPC. How does the RPC call the correct RPC that i wanted?

    [PunRPC]
    public void ActivateSkillRPC(Vector3 position)
    {
        _targetPos = position;
        _casting = true;
        _castingTimer = CurrentLevelSkillStat.castTime;
    }

    [PunRPC]
    public void ActivateSkillRPC(int viewID)
    {
        EntityBase ent = PhotonNetwork.GetPhotonView(viewID).GetComponent<EntityBase>();
        _targetEntity = ent;
        _casting = true;
        _castingTimer = CurrentLevelSkillStat.castTime;
    }

Comments

  • Hi @scmulagah,

    it depends on the parameters you add to the RPC call. If you add a Vector3, the first [PunRPC] marked function gets called. If you add an int, the second [PunRPC] marked gets called. If you add a float or something else, you will receive an error message logged to the console.

    As an example: photonView.RPC("ActivateSkillRPC", RpcTarget.All, Vector3.zero); will call the first [PunRPC] marked function.
    photonView.RPC("ActivateSkillRPC", RpcTarget.All, 0); will call the second [PunRPC] marked function.
  • scmulagah
    Options

    Hi @scmulagah,

    it depends on the parameters you add to the RPC call. If you add a Vector3, the first [PunRPC] marked function gets called. If you add an int, the second [PunRPC] marked gets called. If you add a float or something else, you will receive an error message logged to the console.

    As an example: photonView.RPC("ActivateSkillRPC", RpcTarget.All, Vector3.zero); will call the first [PunRPC] marked function.
    photonView.RPC("ActivateSkillRPC", RpcTarget.All, 0); will call the second [PunRPC] marked function.

    Thanks. I worked around it, by passing an index from the skills. Seems easier and cleaner that way