High RTT with client and host on same pc

Hi, I’m having a problem with the latency of my game.
With a frame rate of 60 and a tick rate of 60 the RTT is approximately 30-40ms, but I don’t understand why, given that on the same PC there should be a latency lower than 1.

Before writing here, I tried many solutions on Unity, none of which totally worked, so I did some tests where I removed everything, and I mean literally everything, from the scene, I left only a UI to start the host or client, and the script that controls that is. I already tried typing the command "ping localhost" on the Windows terminal and it returns a ping less than 1, but still on Unity the RTT is high.

Note: The delay is only on the client, and on the host it is 0, (I think this is normal).

Sorry if some of what I wrote might be obvious, but I’m fairly new to Netcode-for-GameObjects.

Any answer would be very helpful, thanks.

3 Answers

3

I haven’t yet used Unity’s new netcode library. However if it does the actual processing on the main thread, you can get a delay of 0 up to twice the frame time (assuming both clients run at the same fps). So when the client sends a packet out, it would be received essentially instantly by the server but it would be processed the next update. When that is happening the server would respond and the client receives the answer also instantly but here we have the same problem that it only processes the message once he runs Update. You could be lucky that update just so happen to run right after the packet arrived, however if not you get some extra time.

As I said I have never used Netcode and I don’t know if it calculates the RTT for you. Some network systems have a so called network or server time. The arrival of packets generally happens asynchronously, but we could write down the exact arrival time. That way each side can calculate the additional processing delay which could be subtracted from the calculated RTT to get the actual ping time. RTT is more than just twice the trip time since it includes the processing time as well.

This is just a guess from my side. I know other network protocols and how they solve latency issues. In Quake3 for example even the client essentially “signs” each input packet it sends to the server with a timestamp. The server of course gets this packet at a later time but can actually backtrack and apply the movement at the point when the user actually pressed the button (up to a certain limit. The user can’t tell the server he shot that player 10 seconds ago). Likewise packets from the server also have a timestamp and both have a synchronised network time. So even the client can apply the snapshot it receives back in time and extrapolate a bit into the future. Since all movement is acceleration based, this can easily be adjusted by time. Q3 is fully server authoritative. So the clients don’t tell the server where they are, they just tell the server their input and the server actually does all the movement. The client does interpolation / extrapolation based on the snapshots of the server.

I’m pretty sure Netcode doesn’t work exactly this way. Since I haven’t used it yet / looked at the implementation I can’t say much about Netcode in particular. So this was just about networking in general and what might be the reason for the delay. What framerates do you have and you are sure that runInBackground is true?

The problem isn’t sending the server input and response; Let me explain better: I was creating a game in which the player sent the input and the NetworkId of the player’s GameObject to the host via ServerRPC, and the host moved the player and synchronized it with NetworkTranform, then I wanted to add the prediction of the client in order to have even less latency, but after realizing that there was latency locally, the client prediction was one more thing that I would add later, because I believe that even if there is no client prediction there shouldn’t be be all this latency local; So I chose to remove everything from the scene and leave only the essential things, I left only the features to start the host and the client, but there is still too high latency. As far as the questions are concerned I have set a frame rate limit which is 60fps and in the NetworkManager component “Run In Background” is true.

Does anyone have a solution to the problem?