RPC problem with PhotonViews

The whole answer can be found below.

Please note: 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! And we offer you support through 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.

RPC problem with PhotonViews

ImNightm4re
2019-09-02 00:28:27

When I send an RPC, simply, the only object that receives it is the SAME PHOTONVIEW that SENT IT but in every instance. Here's the code, just for debugging.

void Update(){  
...

if (Input.GetKeyDown(KeyCode.F) && timerPush >= cdPush)  
            {  
                timerPush = 0;  
                Debug.Log("PULSANDO F");  
                Push();  
            }  
}

 void Push()  
    {  
           this.photonView.RPC("PushBack", RpcTarget.Others);  
    }

[PunRPC]  
    void PushBack(PhotonMessageInfo info)  
    {  
            Debug.LogWarning("RPC RECEIVED BY " + this.photonView.ViewID + " THAT CORRESPONDS TO " +   
            this.photonView.Owner.NickName + " that was sent by " + info.photonView.Owner.NickName + " with ID "+   
            info.photonView.ViewID);  
        if (this.photonView.IsMine && info.photonView.ViewID != this.photonView.ViewID)  
        {

            gameObject.transform.position = new Vector3(0, 0, -1.2f);  
        }  
}  

I also get this error that I dont know what it means.

  
NullReferenceException: Object reference not set to an instance of an object  
Photon.Pun.PhotonNetwork.ExecuteRpc (ExitGames.Client.Photon.Hashtable rpcData, Photon.Realtime.Player sender) (at Assets/Photon/PhotonUnityNetworking/Code/PhotonNetworkPart.cs:506)  
Photon.Pun.PhotonNetwork.OnEvent (ExitGames.Client.Photon.EventData photonEvent) (at Assets/Photon/PhotonUnityNetworking/Code/PhotonNetworkPart.cs:1997)  
Photon.Realtime.LoadBalancingClient.OnEvent (ExitGames.Client.Photon.EventData photonEvent) (at Assets/Photon/PhotonRealtime/Code/LoadBalancingClient.cs:2782)  
ExitGames.Client.Photon.PeerBase.DeserializeMessageAndCallback (ExitGames.Client.Photon.StreamBuffer stream) (at C:/Dev/photon-sdk-dotnet/PhotonDotnet/PeerBase.cs:640)  
ExitGames.Client.Photon.EnetPeer.DispatchIncomingCommands () (at C:/Dev/photon-sdk-dotnet/PhotonDotnet/EnetPeer.cs:544)  
ExitGames.Client.Photon.PhotonPeer.DispatchIncomingCommands () (at C:/Dev/photon-sdk-dotnet/PhotonDotnet/PhotonPeer.cs:1535)  
Photon.Pun.PhotonHandler.FixedUpdate () (at Assets/Photon/PhotonUnityNetworking/Code/PhotonHandler.cs:116)  

I guess it "cant see" the others photonView... I just don't know. I'm stuck at this point for 2 whole days doing debug but I can't find anything.

Comments

JohnTube
2019-09-02 09:33:06

Hi @ImNightm4re,

Thank you for choosing Photon!

  • Make sure the component that has the RPC method is attached to the same GameObject as the one that has the PhotonView, not its child nor its parent.
  • Make sure there is no other "PushBack" method with different signature in there.
  • Make sure the "PushBack" method is not static.
  • Make sure there is only one instance of the component that has the RPC method attached to the GameObject.

ImNightm4re
2019-09-02 09:58:42

Thank you for the response!

  1. Yes, it's in the same GameObject
  2. No, there isn't.
  3. No, it's not static.
  4. Yes, there's just one.

When I start the game, it'd look like this:

In each instance of the game I have 2 GameObjects -> Player 1 and Player 2. Each one with a different PhotonView ID, one controlled locally and the other isn't. Each GameObject has "PlayerMovement" script where the RPC is.

JohnTube
2019-09-02 16:08:59

Hey @ImNightm4re,

What PUN version are you using?
In PhotonServerSettings do you see the RPC "PushBack" in the RPCs shortcuts list from the inspector in the Unity Editor?

ImNightm4re
2019-09-03 22:31:48

Sorry for the late response but I wasn't at home. My Photon version is 2.13 and yes, I do see "PushBack" in RPCs list.

ImNightm4re
2019-09-03 23:32:05

Just updated to 2.14*

ImNightm4re
2019-09-05 01:05:44

Maybe that helps. When I add another argument to the RPC like "int wtf", I get the following message instead.

PhotonView with ID 2001 has no method "PushBack" that takes 1 argument(s): Int32  
UnityEngine.Debug:LogError(Object)  
Photon.Pun.PhotonNetwork:ExecuteRpc(Hashtable, Player) (at Assets/Photon/PhotonUnityNetworking/Code/PhotonNetworkPart.cs:532)  
Photon.Pun.PhotonNetwork:OnEvent(EventData) (at Assets/Photon/PhotonUnityNetworking/Code/PhotonNetworkPart.cs:1997)  
Photon.Realtime.LoadBalancingClient:OnEvent(EventData) (at Assets/Photon/PhotonRealtime/Code/LoadBalancingClient.cs:2752)  
ExitGames.Client.Photon.PeerBase:DeserializeMessageAndCallback(StreamBuffer) (at C:/Dev/photon-sdk-dotnet/PhotonDotnet/PeerBase.cs:640)  
ExitGames.Client.Photon.EnetPeer:DispatchIncomingCommands() (at C:/Dev/photon-sdk-dotnet/PhotonDotnet/EnetPeer.cs:552)  
ExitGames.Client.Photon.PhotonPeer:DispatchIncomingCommands() (at C:/Dev/photon-sdk-dotnet/PhotonDotnet/PhotonPeer.cs:1548)  
Photon.Pun.PhotonHandler:Dispatch() (at Assets/Photon/PhotonUnityNetworking/Code/PhotonHandler.cs:193)  
Photon.Pun.PhotonHandler:FixedUpdate() (at Assets/Photon/PhotonUnityNetworking/Code/PhotonHandler.cs:127)

JohnTube
2019-09-05 09:55:11

Hi @ImNightm4re,

PUN can't find the "PushBack" RPC method on the receiving end.
It looks like "PlayerMovement" is not attached to the same GameObject as the PhotonView.

The NullReferenceException will be fixed in the next PUN2 update, basically, it's an exception in the code that tells you that there is no suitable method for the received RPC.

If you still have issues with this, send us a minimal repro project at [email protected].

ImNightm4re
2019-09-14 13:23:02

Ok, so I had 2 scripts "PlayerMovement" attached to the gameObject and that seems to have been causing the error... Thank you and sorry about that post o:) .

Back to top