Search Unity

Question Netcode for Entities Relay support explanation?

Discussion in 'NetCode for ECS' started by joshrs926, Sep 25, 2023.

  1. joshrs926

    joshrs926

    Joined:
    Jan 31, 2021
    Posts:
    115
    I'm reading through the Relay Support sample code in the Netcode for Entities sample project and trying to get a grasp on what's going on. It's a bit hard to keep track of what is strictly necessary for simply supporting Relay for Netcode for Entities vs what is unique to this sample project e.g. the unique GUI, the fact there are different sample games to play, supporting various configurations a user might want, etc. I'll continue to study this and I'm sure I'll figure it all out, but I figured I'd ask here in case anyone already knows the answer and can speed this up for me.

    Could anyone explain in simple terms the steps required to set up a client hosted game using Relay and Netcode for Entities?
     
  2. miniwolf_unity

    miniwolf_unity

    Unity Technologies

    Joined:
    Apr 10, 2018
    Posts:
    138
    Generally the steps are like this:
    1. Authenticate a player (host + players)
    2. Create an allocation and request a join code (host)
    3. Passing the configuration to the driver construction
    4. Starting/joining the game (host + players)
    ConnectingPlayer.cs handles the player side for these 4 steps
    HostServer.cs handles the host side for these 4 steps
    NetcodeSetup/RelayDriverConstructor.cs handles the driver configuration after the systems have finished their tasks and you start/join the session.

    The reason for the complexity is that the Relay service methods are async. That means that we have to wait for the task to be finished before we can do the next one.
    One could await these methods which will remove the complexity but will create a blocking call until the handshake, allocation, and join code handling is done.

    Hope that gave a quick overview.
     
    joshrs926 likes this.
  3. joshrs926

    joshrs926

    Joined:
    Jan 31, 2021
    Posts:
    115
    @miniwolf_unity Thanks for the reply. I'm not a master of async await but I thought the whole point of it was to not block the main thread. Why would calling await on the various Relay methods create blocking calls?
     
  4. miniwolf_unity

    miniwolf_unity

    Unity Technologies

    Joined:
    Apr 10, 2018
    Posts:
    138