Search Unity

  1. We are migrating the Unity Forums to Unity Discussions. On July 12, the Unity Forums will become read-only. On July 15, Unity Discussions will become read-only until July 18, when the new design and the migrated forum contents will go live. Read our full announcement for more information and let us know if you have any questions.

Feedback Issue in example for 1.8.0

Discussion in 'Netcode for GameObjects' started by bugfinders, Feb 2, 2024.

  1. bugfinders

    bugfinders

    Joined:
    Jul 5, 2018
    Posts:
    2,256
    In the below code (from https://docs-multiplayer.unity3d.com/netcode/current/advanced-topics/message-system/rpc/) , doesnt PingRpc need a parameter ??

    Code (CSharp):
    1. [Rpc(SendTo.Server)]
    2. public void PingRpc(int pingCount)
    3. {
    4.     // Server -> Clients because PongRpc sends to NotServer
    5.     // Note: This will send to all clients.
    6.     // Sending to the specific client that requested the pong will be discussed in the next section.
    7.     PongRpc(pingCount, "PONG!");
    8. }
    9.  
    10. [Rpc(SendTo.NotServer)]
    11. void PongRpc(int pingCount, string message)
    12. {
    13.     Debug.Log($"Received pong from server for ping {pingCount} and message {message}");
    14. }
    15.  
    16. void Update()
    17. {
    18.     if (IsClient && Input.GetKeyDown(KeyCode.P))
    19.     {
    20.         // Client -> Server because PingRpc sends to Server
    21.         PingRpc();
    22.     }
    23. }
     
  2. NoelStephens_Unity

    NoelStephens_Unity

    Unity Technologies

    Joined:
    Feb 12, 2022
    Posts:
    293
    This is a known issue in the documentation and it does need a parameter:
    Code (CSharp):
    1. private int m_Count;
    2.  
    3. void Update()
    4. {
    5.     if (IsClient && Input.GetKeyDown(KeyCode.P))
    6.     {
    7.         // Client -> Server because PingRpc sends to Server
    8.         m_Count++;
    9.         PingRpc(m_Count);
    10.     }
    11. }
    The documentation should be updated soon with fixes to a few known existing issues in the most recent update.
     
    bugfinders likes this.