Search Unity

Third Party [Photon] Is it possible to make an RPC call on another photonView

Discussion in 'Multiplayer' started by klerta, Mar 21, 2020.

  1. klerta

    klerta

    Joined:
    Apr 15, 2018
    Posts:
    10
    Every example I have seen of RPC calls, then it has always been in the same script as the [PunRPC] function. I have tried to make it happen but it didn't work. Here is the error message:
    upload_2020-3-21_17-51-56.png

    Is it somehow possible to send information to another photonView?

    Edit: I did some research in the Photon docs and found out that by design, the script that has the RPC methods needs to be attached to the exact same GameObject as the PhotonView not its parent nor its child. So it cannot be static.
     
    Last edited: Mar 21, 2020
    goldcloud144 and MilenaRocha like this.
  2. Munchy2007

    Munchy2007

    Joined:
    Jun 16, 2013
    Posts:
    1,735
    Check out RaiseEvent, you can use it to send messages to any client(s) from any script.
     
    goldcloud144 likes this.
  3. klerta

    klerta

    Joined:
    Apr 15, 2018
    Posts:
    10
    I saw the RaiseEvent thing too, but it seems very complicated
     
  4. Munchy2007

    Munchy2007

    Joined:
    Jun 16, 2013
    Posts:
    1,735
  5. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,070
    RPCs call a method on a specific networked object. The object must have the script and be instantiated (have a valid viewID). If something is not working, drop all parameters in the call and the method definition and try again.

    In doubt, check the Basics Tutorial (we use RPCs in there) or mail us a minimal repro (one mostly empty scene, ready to run and debug). To: developer@exitgames.com
     
    goldcloud144 likes this.
  6. JacksparrowPhillip

    JacksparrowPhillip

    Joined:
    May 22, 2019
    Posts:
    14
    yes it is possible. u just have to modify the source code a little bit.
    1 open PhotonView.cs ,define :
    public List<MonoBehaviour> ObserveOtherRPC = new List<MonoBehaviour>();
    2 find the
    RefreshRpcMonoBehaviourCache() method ,add :
    this.RpcMonoBehaviours.AddRange(this.ObserveOtherRPC);line in it
    3 open PhotonNetworkPart.cs ,fix the errors.

    4 in the editor inspector,assign the Monobehaviour script that has [PunRpc] attribute u want to call to the other photonview (u might want to switch the inspector mode from normal to debug in order to see the ObserveOtherRPC that we defined earlier.)
    and all done , u can call any other PRC method with any other photonview u want,just remember to assign properly after the code modification