Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question High latency with relay server in NetCode for Entities Samples project

Discussion in 'NetCode for ECS' started by te_headfirst, Aug 24, 2023.

  1. te_headfirst

    te_headfirst

    Joined:
    Aug 1, 2023
    Posts:
    8
    Hi,

    I downloaded the NetCode for Entities Samples project and ran the Sample -> Astroids via our relay server and also via DirectConnect.

    In MultiPlayer Tool Window:
    Latency via Relay Server showed 400 ms+/- (without any clients connecting apart from myself)
    Latency via DirectConnect showed 10 ms+/-

    Tried downloading and running BossRoom NetCode for GameObjects sample, and on our relay server it ran without latency issues. (even with two clients connecting from different physical locations)

    I tried to upgrade all outdated packages in NetCode for Entities Samples to latest versions (as of today 24 aug 2023) but the latency of 400 ms+/- via Relay Server remains the same.

    I would expect NetCode for Entities to be at least as performant as NetCode for GameObjects, so what could be the problem? Is there some additional configuration needed in the samples project?

    /best regards
     

    Attached Files:

  2. simon-lemay-unity

    simon-lemay-unity

    Unity Technologies

    Joined:
    Jul 19, 2021
    Posts:
    359
    Assuming you use the Relay support code from here, I think the problem might be that the sample is picking an arbitrary region, instead of picking the best one based on latency. To check if this is the case, you could try modifying this line to read as follows:
    Code (CSharp):
    1. allocationTask = RelayService.Instance.CreateAllocationAsync(RelayMaxConnections, null);
     
    NikiWalker likes this.
  3. te_headfirst

    te_headfirst

    Joined:
    Aug 1, 2023
    Posts:
    8
    Thank you for your response.
    I tried setting the region to null and now it connects with 60ms+/-
    I manually tried to set targetRegion to various regions near me, but best latency was still 60ms+/-
    This is definitely an improvement but still some 20 - 40 ms above expected when comparing to BossRoom sample.
    Is this because the BossRoom sample predicts client side and NetCode Entities sample does not?
    Problem is e.g. in the Astroids sample that with 60ms you still clearly notice on your own screen that the projectile goes through the meteor before it is destroyed.
     
  4. simon-lemay-unity

    simon-lemay-unity

    Unity Technologies

    Joined:
    Jul 19, 2021
    Posts:
    359
    Maybe a difference between how Netcode for Entities and Netcode for GameObjects measure RTT? Unfortunately I'm not familiar with how Netcode for Entities measures that. Maybe someone from the Netcode team will be able to shed some light on this.
     
  5. CMarastoni

    CMarastoni

    Unity Technologies

    Joined:
    Mar 18, 2020
    Posts:
    774
    In Netcode for Entities the RTT is measured at the net of the processing time performed by the either the server and it is updated every time an RPC, snapshot and commands are received, and it is usually estimate the current round trip time quite decently.

    In that RTT, in our sample case and in the editor more specifically, we need also to include the fact there is at the very least 1 frame extra delay in that value, if not because the client and server updates in the same frame, but the server will receive the data from the client at the beginning of the next tick. So, on average we need to account at least another 16ms or more on average (because the server receive at fixed time step, not as soon as possible).