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:
How to connect the Netcode for Gameobjects to the Lobby system.
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.
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!
[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: Lobby Quick Join is not working? )
The path I am following is:
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: Unity Relay
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)
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: Unity Lobby
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.
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:
Initialize Unity Services
Sign In Anonymously
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.
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 Manage profiles
public async Task InitializeUnityServicesAsync()
{
var options = new InitializationOptions();
if (ClonesManager.IsClone())
{
options.SetProfile(ClonesManager.GetArgument());
}
await UnityServices.InitializeAsync(options);
}
Now I will do some remote tests and organize my code lol
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.
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:
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?
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.
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.)
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)?
Will there be samples available in netcode for entities 1.2?
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.