Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Resolved Call GetCurrentRtt() from client?

Discussion in 'Netcode for GameObjects' started by Qirka, Jul 31, 2023.

  1. Qirka

    Qirka

    Joined:
    Mar 15, 2021
    Posts:
    2
    I am trying to call GetCurrentRtt to get the ping on the client itself, because I am trying to get more accurate client-side predictions. This is my code:

    Code (CSharp):
    1. if (IsOwner) {
    2.     var clientId = NetworkManager.Singleton.LocalClientId;
    3.     var ping = NetworkManager.Singleton.NetworkConfig.NetworkTransport.GetCurrentRtt(clientId);
    4. }

    But I recieve this warning:

    Is this a bug or supposed to happen, because in the documentation there is not stated that GetCurrentRtt() needs to be called by the server? https://docs.unity3d.com/Packages/c...NetworkTransport_GetCurrentRtt_System_UInt64_
    Or is it because the transport id - client id map may be private? If so, then the warning should mention that.

    Calling my code as a ServerRpc and sending the client-Id with it works correctly and returns the Rtt of that client-Id, but I do not want to use serverrpc for this.

    Or does anybody has a btter idea how to calculate something like a ping/delay on the client itself? Calculating localtime - servertime gives to unprecise results and often also very impossible results, at least when testing using ParrelSync.

    Thanks in advance.
     
  2. simon-lemay-unity

    simon-lemay-unity

    Unity Technologies

    Joined:
    Jul 19, 2021
    Posts:
    416
    You need to pass the client ID of the remote peer you want the RTT for. So if calling this on the client, you want to pass in the ID of the server (which can be obtained with
    NetworkManager.ServerClientId
    ).

    Hope that helps!
     
    Qirka likes this.
  3. Qirka

    Qirka

    Joined:
    Mar 15, 2021
    Posts:
    2
    Wow, thanks for the fast reply, this works. I had no clue that you have to pass the id of something ELSE to sort of ping at, and not your OWN client id... maybe it's me, since I also found some other posts on the internet complaning that GetCurrentRtt always returns 0, so I was a bit biased, or maybe the documentation could describe this better?

    In any case, thank you and have a nice week!
     
  4. hawaiian_lasagne

    hawaiian_lasagne

    Joined:
    May 15, 2013
    Posts:
    120
    Lol this is bananas. Why are we passing the ServerClientId?