Search Unity

Question Can't connect Netcode for Entities to Lobby and Relay

Discussion in 'NetCode for ECS' started by aducceschi, Jun 17, 2022.

  1. aducceschi

    aducceschi

    Joined:
    Feb 9, 2022
    Posts:
    39
    Hi, I've recently been able to connect multiple instances of a game that uses Entities by using the tutorial provided by Unity. I wanted then to connect users by using the Relay and Lobby systems. So I implemented the Lobby system by examining and reusing the HelloWorldSample functions.

    I managed to connect two different PCs with the Lobby system and managed to join the two instances in the same lobby.

    So here is the problem:

    I can't make the Netcode for Entities system use the Lobby system at all. They don't seem to be automatically connected or anything.

    And I can't find any sort of tutorial or sample project in which the two things are connected. The only two samples that Unity provided show:
    1. How to connect the Netcode for Gameobjects to the Lobby system.
    2. How to connect two PCs using the direct IP system for Netcode for Entities.

    Does anyone know how to connect both systems? Any help will be greatly appreciated.
     
  2. Krooq

    Krooq

    Joined:
    Jan 30, 2013
    Posts:
    196
    aducceschi likes this.
  3. aducceschi

    aducceschi

    Joined:
    Feb 9, 2022
    Posts:
    39
    Thanks! Right now I left the Multiplayer part of my game on hold until Unity creates some documentation on Netcode for Entities + Relay. But I'll check out the link you gave me!
     
  4. JJunior

    JJunior

    Joined:
    May 22, 2019
    Posts:
    53
    [edit] I missread your post, maybe because I had just woken up lol But at the end of the day I was doing exactly what you wanted to do, read my last message, it has the code that connects to the lobby and uses the relay to connect the players. I hope it helps. [/edit]

    Aducceshi, I think the best way to start are the demos and the Lobby and Relay docs. I just start implementing the a lobby system with auto connect and had some issues (here is thread opened yesterday: https://forum.unity.com/threads/lobby-quick-join-is-not-working.1312230/)

    The path I am following is:

    1. Installed the "Simple Relay Sample'' from the relay package and played around with it, its a really one script sample example, very good to understand the flow of the relay system with the docs support: https://docs.unity.com/relay/introduction.html

    2. I need a quick join system without the needing of passing codes to the clients, so I implemented a quick lobby join (code attached, not ready yet, but I hope it can help you)

    3. To the lobby system I am using the "Lobby Hello World" sample from the lobby package, its another very simple one script sample and is very good to understand the flow along side with the lobby documentation: https://docs.unity.com/lobby/unity-lobby-service-overview.html

    4. Now I am trying to undertand how to integrate the lobby flow with the NetworkManager, and in a near future I want to do it with a dedicated server approach. As soon as I realize how to put all these pieces toguer I will let you know, probably today I will get it.

    I had some issues using the QuickJoinLobbyAsync so went to an approach using the QueryLobbiesAsync, and its quite working lol as described in my Lobby Quick Join is not working? Thread.

    I think the next step is the Boss Room sample, but I do have the time now to see all the demo, and just want the quick connection to do some initial tests.

    I hope this can help you somehow, and another important documentation resource is this: https://docs-multiplayer.unity3d.com/netcode/current/about

    I will keep posting some updates in my quick connection thread.

    Best Regards
     

    Attached Files:

    Last edited: Jul 22, 2022
    aducceschi likes this.
  5. JJunior

    JJunior

    Joined:
    May 22, 2019
    Posts:
    53
    Humm, I just realized how to use the Lobby + Relay API

    For some reason I thought the Lobby API would be auto integrated with the Relay system, now I am really getting to the point of your question.

    I did a very basic integration with Lobby + Relay + NetworkManager, code attached.

    The flow I am using is:

    1. Initialize Unity Services
    2. Sign In Anonymously
    3. Here we have two different paths, one for the host player and one for the client player
    3.1 Host Player
    3.1.1 The host will be the one that creates the lobby and the relay allocation
    3.1.2 The lobby and the relay allocation are created if the player connecting does not find a named lobby
    3.1.3 If the queried lobby does not exist the player creates it, but before creating the lobby the player creates a relay allocation and gets its join code. With the join code the player creates the lobby passing the Join code into the lobby data. This lobby data can be accessed for the client players
    3.1.4 After creating the lobby and the relay allocation the player starts the NetworkManager as a host​
    3.2 Client Player
    3.2.1 the client player searches for the named lobby, as it was already created by the host the player just need to connect to the lobby
    3.2.2 After connecting to the lobby the player gets the relay join code and joins the relay allocation
    3.2.3 After joining the relay allocation the player starts the NetworkManager as a client​

    That's it, maybe my explanation is confusing, but the code is very simple.

    It's quite working, I am just having a "player is already a member of the lobby" when joining as client player, that is why the authentication service is using the same player, I will look for a way to auth with too different players and it should work. I will keep you posted.
     

    Attached Files:

    aducceschi likes this.
  6. JJunior

    JJunior

    Joined:
    May 22, 2019
    Posts:
    53
    Its working!!! I just changed the InitializeUnityServicesAsync method. As I am using ParrelSync, I just use the argument to set the player profile. Yes, I just discovered this ProfileManagement thing https://docs.unity.com/authentication/ProfileManagement.html

    Code (CSharp):
    1. public async Task InitializeUnityServicesAsync()
    2.     {
    3.         var options = new InitializationOptions();
    4.  
    5.         if (ClonesManager.IsClone())
    6.         {
    7.             options.SetProfile(ClonesManager.GetArgument());
    8.         }
    9.  
    10.         await UnityServices.InitializeAsync(options);
    11.     }
    Now I will do some remote tests and organize my code lol
     

    Attached Files:

    aducceschi likes this.
  7. aducceschi

    aducceschi

    Joined:
    Feb 9, 2022
    Posts:
    39
    Thank you so much for the info and script!! Tomorrow I'll try to implement it and I'll tell you if it works for me!
     
    JJunior likes this.
  8. JJunior

    JJunior

    Joined:
    May 22, 2019
    Posts:
    53
    Aducceshi, I just changed the code to use the quick join, it's now working after I changed the code to use different profiles from the different clients I was using to test.
     

    Attached Files:

    aducceschi likes this.
  9. aducceschi

    aducceschi

    Joined:
    Feb 9, 2022
    Posts:
    39
    Hey, I tried your code but I can't even get it to compile because there's some packages missing apparently.
    It says it requieres Unity.NetCode.Transports.UTP. And it also requires a "NetworkManager" and a "Transport" Classes. Are you using Unity Netcode for Entities? Because this is stuff from the Netcode for GameObjects. And I cannot install the Gameobjects package because it conflicts with the Entities package.
    I get this errors if I try to install both packages at once:
    Screenshot 2022-07-30 at 12.05.24.png

    Screenshot 2022-07-30 at 11.59.29.png
     
  10. JJunior

    JJunior

    Joined:
    May 22, 2019
    Posts:
    53
    Yes, I am using the Netcode for GameObjects :S
     
    aducceschi likes this.
  11. druffyw

    druffyw

    Joined:
    Mar 1, 2019
    Posts:
    1
    Facing the same general problem.

    We did get the NetcodeSamples examples on Netcode for Entities to connect over our relay server, but when digging through the code it seems like a lot, A LOT, more hand coding is needed with NetCode for Entities than for NetCode for GameObjects.

    Also we se limited or no support for e.g. Steam Relay services.

    Have you found any decent tutorials or have you paused the multiplayer part for now?

    Currently browsing through the latest from here https://www.youtube.com/@MemphisGameDevs/videos
     
    Last edited: Aug 31, 2023
    aducceschi likes this.
  12. aducceschi

    aducceschi

    Joined:
    Feb 9, 2022
    Posts:
    39
    Haven't found any Steam Relay service support unfortunately, I've completely paused multiplayer for now.
     
  13. te_headfirst

    te_headfirst

    Joined:
    Aug 1, 2023
    Posts:
    18
    In the same boat here... Currently trying to get an idea about whether or not Steam Relay Support in Netcode for Entities is in Unitys roadmap in any near future. The impression is that DOTS/ECS is being prioritized but then again whether that includes support for other services other than UGS is still in the dark. Will update here if we pick up news.
     
    aducceschi likes this.
  14. simon-lemay-unity

    simon-lemay-unity

    Unity Technologies

    Joined:
    Jul 19, 2021
    Posts:
    441
    I know this isn't the most straightforward way to go about it, but it is possible to write custom network interfaces for Unity Transport (which is what Netcode for Entities uses under the hood). Custom interfaces would allow writing an integration for (say) Steam's relay service. A user attempted it here, and you can find more details about the challenges involved here.

    Regarding whether this is something we (Unity) plan on providing ourselves, all I can say is that it is not on our immediate roadmap. That doesn't mean that the door is closed and we won't do it, just that we're not working on that currently. (We do however plan on making it easier to write custom network interfaces for Unity Transport. The next version of the package should contain changes related to that.)
     
    Last edited: Sep 6, 2023
    te_headfirst and aducceschi like this.
  15. PaulMucci13

    PaulMucci13

    Joined:
    Sep 8, 2023
    Posts:
    1
    I wish there were samples on how to get a simple lobby working with Netcode for Entities.
     
    te_headfirst, horeaper and aducceschi like this.
  16. CMarastoni

    CMarastoni

    Unity Technologies

    Joined:
    Mar 18, 2020
    Posts:
    895
    Added to the backlog! :D
     
    aducceschi likes this.
  17. joshrs926

    joshrs926

    Joined:
    Jan 31, 2021
    Posts:
    115
    I would love to see a sample for this too
     
    te_headfirst likes this.
  18. te_headfirst

    te_headfirst

    Joined:
    Aug 1, 2023
    Posts:
    18
    Pinging with some questions :)
    1. Any update on this (or revised recommendations for what actions to take to get e.g. lobby functionality, steam relay services etc. using netcode for entities)?
    2. Will there be samples available in netcode for entities 1.2?
    3. Any news on when 1.2 will hit the shelves? :)
     
  19. IAmChiagozie

    IAmChiagozie

    Joined:
    Jun 26, 2017
    Posts:
    44
    Following to get updates on this.
    I've been stuck here for 4 days now trying to get Netcode for Entities to connect with unity relay. It kept saying something along the lines of "invalid address" when listening to the relay's provided IP and port, and the client world is stuck connecting to the same address.

    I will put my multiplayer plans on hold for now until a solution becomes available.