Search Unity

Third Party PunRPC methods are not working after updating PUN 2

Discussion in 'Multiplayer' started by laranthir, Dec 2, 2021.

  1. laranthir

    laranthir

    Joined:
    Oct 6, 2019
    Posts:
    5
    I've recently updated my PUN 2 package from asset store to fix a problem which was not getting userIDs when a player entered/left a room. (OnPlayerEnteredRoom callback)

    The solution was to update the PUN 2 to newer versions on this forum topic.


    After updating the PUN 2 plugin, all the PunRPC tagged methods started giving an error.



    The PunRPC methods that worked before I updated are now throwing this error at me. Weirdest part is, they are giving this error even when I don't call these methods named "Fire" and "SpawnBossTrigger" because these methods are from another Scene which is not even loaded yet. I'm on Menu scene, these methods are from the Ingame Scene. And the actual method I'm calling is this:

    Code (CSharp):
    1. [PunRPC]
    2. public void CheckIfPartyLeader()
    3. {
    4.     if (PhotonNetwork.LocalPlayer.IsMasterClient)
    5.     {
    6.         SetPartyLeader(PlayerContainer.Shared.playerProfile.nickname);
    7.         StorePartyLeaderIDLocally(PlayerContainer.Shared.playerProfile.nickname);
    8.         PlayerContainer.Shared.isPartyLeader = true;
    9.        
    10.         gameObject.GetComponent<PhotonView>().RPC("SetPartyLeader", RpcTarget.OthersBuffered,
    11.             PlayerContainer.Shared.playerProfile.nickname);
    12.         gameObject.GetComponent<PhotonView>().RPC("StorePartyLeaderIDLocally", RpcTarget.OthersBuffered,
    13.             PlayerContainer.Shared.playerProfile.nickname);
    14.     }
    15. }
    Which is used to set the party leader in a room. I don't get whats wrong. This is from my PartyManager script. And it has a Photon View component attached to it as well.


    Code (CSharp):
    1. [PunRPC]
    2. public void KickPartyMember(string userID)
    3. {
    4.     Debug.Log("KickPartyMember function worked.");
    5.     if (PhotonNetwork.LocalPlayer.UserId == userID)
    6.     {
    7.         Debug.Log("You're kicked from the party.");
    8.         LeaveParty();
    9.     }
    10. }
    11.  
    12. [PunRPC]
    13. public void KickButtonMethod(string userID)
    14. {
    15.     Photon.Realtime.Player kickTarget = null;
    16.     foreach (var player in PhotonNetwork.CurrentRoom.Players)
    17.     {
    18.         if (player.Value.UserId == userID)
    19.         {
    20.             kickTarget = player.Value;
    21.             break;
    22.         }
    23.     }
    24.  
    25.     if (kickTarget != null)
    26.     {
    27.         gameObject.GetComponent<PhotonView>().RPC("KickPartyMember", kickTarget , userID);
    28.         Debug.Log("Kick Button worked.");
    29.     }
    30.     else
    31.     {
    32.         Debug.Log("KickTarget is null.");
    33.     }
    34. }

    This above is the kick function, which gives the same error but with another PunRPC method's name from another scene (which is not even active?).






    Here is the Photon View component attached to same game object with the script. And this function is non-static and in no way related to "SpawnBossTrigger" or "Fire" PunRPCs. This error appears whenever I call these CheckIfPartyLeader or KickPartyMember RPC methods.


    Any ideas on what I'm missing?


    Sorry for the long post, thank you for reading.

    - Laranthir
     
  2. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,072
    How is that meant?

    Maybe you should re-calculate the RPC list. PhotonServerSettings, RPC foldout. There is a button to "Refresh RPCs".
    I assume the PartyManager is on the object within the scene? Not added at runtime?

    You could possibly try to implement a new RPC and call that. Does it run into the same error?
     
  3. laranthir

    laranthir

    Joined:
    Oct 6, 2019
    Posts:
    5
    Hey tobi,

    Party Manager is on the object within the scene, not added at the runtime. All those RPC function names within the errors are not even on the same scene, their script is also not on the same scene. They are completely irrelevant.

    I tried implementing multiple new RPC methods that do the same with different method names etc, they ended up with the same/similar results.

    I tried the refresh button and checked the list. When I clicked on the KickPartyMember button, It gave me the wrong RPC error again from 13th index. upload_2021-12-3_19-12-49.png
     
  4. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,072
    RPCs are not implemented per scene.
    In fact, unless you synchronize the scene via PUN itsel, it doesn't mind which scene is loaded everywhere.
    It seems that some client is running another scene or that your scene loading is not synced.
    Or .. you could be buffering RPCs. The server's event buffer also doesn't mind which scene the RPC was called from. It will send the buffered RPCs to joining players, no matter which scene it is.
     
    laranthir likes this.
  5. laranthir

    laranthir

    Joined:
    Oct 6, 2019
    Posts:
    5
    If I understood you correctly, I'll try and tell you the results. Thank you.
     
  6. laranthir

    laranthir

    Joined:
    Oct 6, 2019
    Posts:
    5
    I couldn't fix the issue myself, a coworker of mine suggested reinstalling the package (incase of obsolete or corrupted files) and it works now. Apparently version control program that we use caused this issue. Thank you for your time anyway. :)
     
  7. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,072
    Glad you could fix it!
     
    laranthir likes this.