❤ Watch my FREE Complete Multiplayer Course ua-cam.com/video/7glCsF9fv3s/v-deo.html 💬 This was one of the most requested UGS tutorials, I hope you find it useful! Best of luck with your Multiplayer games! ✅ Learn more about Lobby and UGS on.unity.com/3XdKEd7 🌍 Get the Project Files unitycodemonkey.com/video.php?v=-KDlEBfCBiU 📝 Lobby Docs on.unity.com/3OtC0Du 🌍 Get my Complete Courses! ✅ unitycodemonkey.com/courses 👍 Learn to make awesome games step-by-step from start to finish. 🎮 Wishlist my Next Steam game! cmonkey.co/totalworldliberation 🔴 RELATED VIDEOS 🔴 COMPLETE Unity Multiplayer Tutorial (Netcode for Game Objects) ua-cam.com/video/3yuBOB3VrCk/v-deo.html Multiplayer through FIREWALL with Relay! (Unity Gaming Services) ua-cam.com/video/msPNJ2cxWfw/v-deo.html What is Unity Gaming Services? ua-cam.com/video/JwClCc2_zC8/v-deo.html EASY Console! Run any Command! (Add Cheats, Set Gravity, Spawn Enemies Quantum Console Asset Review) ua-cam.com/video/bOf6CjpuSFs/v-deo.html Simple Text Input Field Window in Unity (Submit Score, Name) ua-cam.com/video/4n6RT805rCc/v-deo.html
I found myself returning to this video often to refresh my memory when building my lobby I wrote down all the time stamps to the sections maybe some one can also use these... 1:54 install packages 2:06 setup services 3:08 script creation / service initialization 5:46 create lobby 8:18 search for lobbies 11:17 implement lobby heartbeat 13:22 add filters to search for lobby 16:55 join lobby by id 18:48 creating lobby options 20:12 join lobby by code 21:16 quick join lobby 23:48 print players 28:06 player creation refactoring 32:33 update game mode 37:30 handle update polling 39:56 updating player names 41:34 leaving lobbies 42:40 kicking players 44:40 transfer host 46:02 deleting lobbies
Thank you! I have referenced this video countless times while implementing Lobbies in my game. It would be great if these were added as chapters to the video.
As someone who's been working with Unity professionally, you never cease to give really great reference to new services and quick implementation, keep up the hard work!
when lobby host left the lobby, for example wifi disapears or game crashes, lobby disapears after 30s from the list, but players in lobby stays endefinetely with no warning that lobby no more exist. is there a way to change lobby owner when original owner is offline?
I have returned to this video approximately 20 times over the last three weeks. It is amazing, giving only what we need and no confusion. I'm actually using what I learn to develop a unity package that incorporates everything here with steam, automatically setting player icons and names and such. Thank you very much for this tutorial, it would have taken me months without
Just a note in case some is facing the same issue. If you are using the editor to test (I am using parrellels sync package), the heartbeat might stop when you unfocus the editor window. You can change it in Edit -> Project Settings -> Player -> Resolution and Presentation -> Run In Background. Also the anonymous login will create the same id for both players when logging in by default. You can either clear the session tokens or use different profiles to get around it.
I just started game developing and it seems like all my ideas that I am excited about are all multiplayer, seems like I timed my start right, thank you for these valuable videos!
Heh nowadays making multiplayer games is easier than ever so that's great timing! I remember when I added Multiplayer to my first Steam game, I had to build the entire Lobby Master Server infrastructure from scratch myself, it was very painful and very easily broken. Really awesome that nowadays there are all these tools you can easily use!
@@ergicela4420 The lobby system in this tutorial is done with the base Unity system and is free as long as you don't use too much data (unless you have a lot of players this won't happen), then the hosting of the server is done by the player that is the host of the lobby. Because of this you don't need to run your own servers and the entire system is free to use. So no you don't have to pay to add multiplayer
If like me you're a newbie and get the error : "player is already a member of the lobby" while trying to join a lobby from different instances of the game, you have to find a way to differentiate the two players (host and client). One way is to change your authentication method like this : private async void Start() { var options = new InitializationOptions(); options.SetProfile("Player" + Random.Range(0, 1000)); await UnityServices.InitializeAsync(options); //
Awesome video. I have come back to this several times while prototyping my own lobbies implementation. Would be super helpful if you included chapters!
when lobby host left the lobby, for example wifi disapears or game crashes, lobby disapears after 30s from the list, but players in lobby stays endefinetely with no warning that lobby no more exist. is there a way to change lobby owner when original owner is offline?
Yes Code Monkey, YES! I'm working on a VR artwork which uses multiplayer, but I had no idea how to setup the lobby, but with this everything is working just fine! Thank you for everything and good luck with the rest!
Love your content. This is the best way to learn new concepts as opposed to reading documentation and thousands of lines of code in example projects. Your videos are extremely helpful and you saved my ass countless times. Thanks!!
Not sure what timestamp you're referring to, what two different variables? You mean lobbyName and maxPlayers? It's to avoid using magic numbers ua-cam.com/users/shortsCQ5xHgRZGQo Sure, you can use a coroutine instead of a float timer. Personally I prefer float timers because I dislike the cumbersome structure that coroutines force you to use. You need a MonoBehaviour, need IEnumerator, need yield return, need StartCoroutine(); whereas with a float timer you just have a simple number. But that's just personal preference.
@@CodeMonkeyUnity Apologies. By the time I got to the end of the video it more or less made sense & I edited the comment, haha 😆. I was referring in particular to the lobby, hostLobby, and then joinedLobby variables. For the sake of "safety", I followed most of your instructions, though I did swap out the Update timers for coroutines as I'm just used to them. My head's swimming a bit as the last 20 minutes of the video really ramped things up a notch, but I was able to keep up well enough & everything looks good! I'll certainly be grabbing your project files to check for reference as I'd like to see how you implemented the UI functionality, particularly for kicking players & such. Thanks so much for all of the amazing tutorials (and I always use Codemonkey10 at checkout now, so many additional thanks for that, too). You rock! \m/(>.
Yes!!! UGS tutorials are amazing! Thank you so much! Can you please make one for Unity Game Server? I cannot find it anywhere on the net outside of docs and a video showing a practical example would be extraordinarily helpful, not just to me but to MANY others.
Im also trying to work that out, and have been through several days... when I download the project files they seem to be a bit broken, so its hard to figure out how the UI gameobjects should be constructed.
Could you possibly make a tutorial on how to make the UI for the lobby and how to connect it to this? I've followed this tutorial but I'm not quite sure how to do that. The main problem I'm having is I'm not quite sure how to get the names of the players in the lobby, but I see you set it up to do that in your UI. Regardless, thank you for making these tutorials for us!
Note that if the 30 seconds lifeapan of the lobbies bugs you, it can be changed via the UGS dashboard up to an hour (3600 seconds). Probably negligeable, but helps send less data, which is always good.
If you are new to unity these tutorials will be somewhat challenging , Because he's using his custom UI stuff instead of unity built in stuff. These tutorials can be simplified a lot.
@@CodeMonkeyUnity how can I switch to the game scene for everyone after creating the relay? Please respond this has been bugging me for the past several weeks
I have a question - as you said in this video, using netcode for game objects, relay and lobbies makes for a seamless multiplayer experience. What is the right video to start watching in order to do that? I don't really understand how they differ and how they work together.
Each of the videos focused on each tool. This one is the lobby video Here is the Relay unitycodemonkey.com/video.php?v=msPNJ2cxWfw And NGO unitycodemonkey.com/video.php?v=3yuBOB3VrCk
I'm getting a bug when I run my game in a standalone build that causes the player to never leave the lobby if I close the game while still inside it. I can force leave the lobby, but closing the game seems to leave the lobby open forever. Any experience with this bug or an idea on how to fix it? UPDATE: I think calling delete lobby or remove player from lobby from OnApplicationQuit works, but only if you don't do it asynchronously (so no async/await in the call).
i have small issue. im using your lobby assets you provided. when player leaves lobby or relay. or shuts down game completely, he stays in the lobby and cant reconect. when im testing lobby always says it has two players, so the host and testing build. i also keep lobby on dontdesroyonload when moving to gameplay scene, just to keep lobby active for new players to join, but i dont think it makes this problem. also in dashboard in lobby i changed so if player is disconected for 10 seconds, he would be removed from looby, it was set on 2 minutes, and still it doesny work, players stays in the lobby no mater what.
Great tutorial very clear! Did you make a video on how to transition from the lobby scene like the one you created to the actual multiplayer gameplay scene?
You can just sync some Lobby data, set it to 0 by default then set it to 1 when you wnat to start the game, that's waht I did in my complete game ua-cam.com/video/7glCsF9fv3s/v-deo.html
Good afternoon! In anticipation of the looby part of the "Learn Unity Multiplayer" video, I just finished the "Making a MULTIPLAYER Game? Join your Players with LOBBY!" video, a very clear and very informative video as usual. Thank you for the passage concerning the prices, I had already read it, but it is reassuring for a non-English speaker to have an additional interpretation. I have many qustions : a) when all players leave the lobby, we get a bunch of errors in the console: - [Lobby]: LobbyNotFound, (16001). Message: lobby not found - HttpException`1: HTTP/1.1 404 Not Found How to manage them? b) I didn't understand why we have 2 lobby variables (hostLobby and joinedLobby). We only have one lobby, don't we? c) At 47:20, you have a using Unity.VisualScripting clause. This happened to me from time to time, and I got into the habit of uninstalling several packages installed by default by Unity: VisualScripting, Visual Studio Code Editor and JetBrains Rider Editor. I have the impression (at 90%) that Visual Studio offers me fewer functions for autocompletion. I would like it to be automatic, but I admit that my first attempts were not convincing :) Thank you very much for this video !
For (a) you would need to set the lobby to null in the catch section of the code, so that the Update function stops the heartbeat to an already deleted lobby. For (b) you can probably modify the code to only use joinedLobby. I'm guessing CM uses two different variable names for teaching clarity. I have no idea about (c). If you don't need that reference in your code, just delete the line. You should keep Visual Studio Code Editor package if you're using the VS IDE to write your code though, I think it's needed for proper integration. Good luck!
I have a question about constructors and initialisers, like at 31:08, u have used curly brackets to pass in the arguments for createLobbyOptions, but on the other other, in some cases, just normal round brackets are used for passing in arguments. How does it exactly work? Thanks for the help!
figured the issue but dont see a fix....When you press Authenticate without changing the name from Code Monkey, it will not authenticate nor let you go back...
Please tell that how can we make a functional search bar on which if we search then it will show the list of online multiplayers And if we click on any player it will show option "add friend" if we click on add friend it will be added to our friends list
I can't even get past the intro before I get an error I can't find a resolution for: "Cannot implicitly convert type 'Unity.Services.Lobbies.Models.Lobby' to 'Lobby'" The code: Lobby lobby = await LobbyService.Instance.CreateLobbyAsync(lobbyName, maxPlayers); I even copied it directly from the website and still got this error. What am I doing wrong? I've added all the exact same "using" at the top of the script even.
@@CodeMonkeyUnity fuck... I did 😅 every time', the simple and easy babe is already taken and I spend days to try and figure out why it didn't when. Thanks!
Thank you for the video!! I have realized one thing that happens sometimes. It might have to do with the fact that most of the code here are async code that when I stop playmode (from testing), time and after the scene changes when exiting playmode - (aka is different to what it was before starting play mode)... usually this is fine as reloading the same scene by clicking in the scene from the project in the editor restores it to what it was before... But I was wondering if this could happen for a build as well? because I had a few times where the camera was getting disabled for no particular reason when exiting playmode and this would be really bad if it happens in a build and remains that way...
question, @CodeMonkeyUnity, you mentioned that its better to create the game as one package, server, host and client... i am planning on making a mobile game... not sure if I should create the "Server" version first, then convert it to or switch type to Mobile after creating the server version... so the client can be mobile.. your thoughts? hoping to do a Dedicated server hosting for unity to host.
Loved the video! Just wanted to ask, why don't you like coroutines? I thought it was standard procedure to keep most of your logic inside coroutines and functions.
Personally I don't like the pattern they force you to use. You need to use a MonoBehaviour, you need to StartCorouting(), you need to make a function that return IEnumerator, you need yield return I find that whole pattern to be needlessly convoluted. But they work perfectly fine, so if you like them then by all means use them
@@CodeMonkeyUnity Those are definitely valid reasons. I guess I'm just more used to them now. Find it much easier to hold execution and sync with fixed updates in coroutines. Just wanted to know if I was missing something here.
I'm using ParrelSync to quickly test the game in another Unity Editor. But by doing this, the second player is assigned the same ID at the start. This means that I keep on getting the error "LobbyConflict, (16003). Message: player is already a member of the lobby." when trying to join. Is there any workaround?
You need to use a different name when Authenticating when running on the same machine, just like I added a input window to give each build a different name.
@@CodeMonkeyUnity Hello! I found a solution right after typing the comment but I think it got automatically deleted because I put a link in it. I used authentication profiles to isolate my players. Here is my Start function: private async void Start() { var options = new InitializationOptions(); playerName = "Player_" + Random.Range(10, 99); options.SetProfile(playerName); await UnityServices.InitializeAsync(options); This way, each player gets assigned an unique ID.
Couple of minor changes I'd make - using multiple lobby variables is a bit confusing. You really just need one. Switching them back and forth isn't necessary since one client is going to be be a part of one lobby at a time. Also, logging into a lobby via code. I think for a tutorial it makes more sense to log in by lobby Id, because that's a value you can actually get. Only the host of the lobby gets access to the lobby's code.
What do you mean multiple Lobby variables? There's just one member variable which is set whenever a function changes it, you need to do that since the variable won't update by itself. If you want to see it as part of a complete game I used this in my complete course ua-cam.com/video/7glCsF9fv3s/v-deo.html
do you have any video showing how to transfer data between host and guest and both of them getting notified on events? Usecase: guest changes its data and host gets notified about changes and viceversa.
Lobby services with 10 gb is neat. Free authentication, remote config and cloud storage. Relay services however can become quite costly**. let's say your game is $15. 30% goes to steam, $5 for simplicity. Then you have your own take of $5. The rest $5 goes back into the game. which means ($5 / $0.16) / 12 ≈ 2,6 years. After that you're paying it yourself to support your own games networking. By then you require another monetization feature just to keep the game running. Or revert back to Direct IP which is troublesome for most players to set up. Most of them don't even know how to access a router / modem let alone configure it for some game. I'm ignoring bandwidth here, but that also is quite costly when you go above 150 gb of data. Multiplayer is great, just not the costs that come with them. ** Sure there are caveats and this calculation is a worst case scenario 100% playtime. It still feels expensive. Perhaps my view on it is too extreme.
Your math is a bit confusing, you're assuming every single player will be online at the exact same time playing 24/7 for 2.6 years, that is an extreme scenario that doesn't really ever happen. Remember it's Concurrent users, not just Users. As an example, my own game Battle Royale Tycoon, which was a decently successful release (for an indie dev) only had a single month above 50 CCUs with 75. So if the game was multiplayer it would have costed me $4 while it sold over $100,000 So to me the math seems really good. If you have thousands of CCUs then your game is a mega-hit which sold hundreds of thousands of copies and those players will not play 24/7 for 2 years.
@@CodeMonkeyUnity That makes a lot more sense. Like I mentioned with the '**' Worst scenario with 100% playtime. But you're right not everyone will play every day for 2 years long. Thanks for explaining
when lobby host left the lobby, for example wifi disapears or game crashes, lobby disapears after 30s from the list, but players in lobby stays endefinetely with no warning that lobby no more exist. is there a way to change lobby owner when original owner is offline?
Is it possible to use this lobby setup, then on start, spin up a dedicated server? I setup matchmaking, but now I want to add the lobby service instead of waiting for random players to join.
Thanks a lot for this great Tutorial. I am having some trouble with connecting a UI to the code though, like you showed at the end. When trying to create the List of existing Lobbys I created a prefab for the list entrys but I can't figure out how to dynamically spawn elements of this prefab and also how to then fill it with the lobby name, maxplayers and so on. I tried taking a look at your project files but i can't figure it out. Also for the UI, I saw you put everything in one Scene - I created multiple Scene for each "Window" - Which route would be considered "correct" according to Unity Guidelines? If your style is the proper way, do you have a Link to a tutorial on how you did that? Again, Thanks a lot!
Hello, just using this right now, I added the team selection on my lobby screen but only the player themselves can edit their PlayerData, not even the host can, so how would you work around this?
Massive thanks for this multiplayer series, and super excited for the upcoming one, I hope you make more and more videos or even courses on multiplayer, DOTS, ECS... I'm sure they'll be very valuable. And I hope I can support with more sizeable donations in the future, being an indie dev making games with nothing released yet is kinda hard on my ressources 🥲
I understand you mentioned how to make the players on team, but it would be great for you to show us. Im not that good of a coder and im lost most of the time. Anyway to make a video on selecting team both manual and random, adding friends, creating parties, thing like that. Seems like alot for me but it might not be that big of a task for you. Thanks even id you say no lol !!
How do you change data for each player, like the avatars you've show in this video and sync it with other players? I've trying to make a team based lobby with no succeed, I have tried to change data of each slot for each player but it does not work, since only the player itself can change his own data and the host of the lobby can't change the data of other players.
Great Video! just want to know if we can customize the lobby code or not.. like if i want it to be for 5 characters only, something like that was present in photon i think!
You would probably only add that during gameplay. After you start the game if there are fewer than the max number of players spawn a bot for the remaining ones
The Lobby deletes itself and doesn't migrate host after the host "unexpectedly" disconnects (simply turning off unity play) instead of just leaving the room. Is there a way around this?
I come with updates! when you poll a lobby for updates you can do special logic only when the lobby has changed. Every lobby has a version which changes whenever the lobby is updated. here's some sample code for checking for updates, put it inside the if statement for when the LobbyPollTimer < 0 Lobby oldLobby = joinedLobby; joinedLobby = await LobbyService.Instance.GetLobbyAsync(joinedLobby.Id); if (joinedLobby.Version != oldLobby.Version) { //your custom logic }
I have some doubts, how host is migrated if host has quit the game suddenly? How Host is migarted without using migrateLobbyHost() by host as host lobby will be null hence no pingheartBeat would be called?
Can you help me with this simple problem? How do I get the player data saved in the lobby, such as name and loadout, in the game when I actually run it? For example displaying the users name to other players? I know it's probably simple but an explanation would be awesome.
Store it in a variable locally on the lobby owner, have that lobby owner start hosting the game, wait for all to be connected, send a ClientRPC to send that data to all clients Or you don't even need the host to send anything, just store in a local variable for each connected player since they know the lobby state
@@CodeMonkeyUnity I'm so sorry could you explain it in more detail? I guess I don't entirely get how the client rpcs work here, like save the variable in the lobby script or the player script? Also how do I connect the PlayerId from the lobby to the networkmanager client id? Are they the same?
No I just ask that how add search bar instead of lobby like I have many players playing online game and one of them want to add another as a friend and he will search his name on the search bar and then add him as a friend
I want to make a great game but I am wary of how much, complex and overbearing trying to learn what's required will be. All Unity basics, csharp+ whatever it's called, all the computer stuff I'm not tech savvy with, if I mess 1 pivotal super important thing and can't undo it, what if loading tests are way too long, what more costs I might need that Idk rn etc.
lol don't worry about sprinting before you can crawl. I've only started learning recently and it is extremely time consuming and tedious BUT I can honestly say its worth every second. If your passionate about something never let something that might not even happen or be a problem you face hold you back, just go
Don't worry, you can always undo everything, if you write some code and it gives an error, you can always find and fix the error, there's no permanent breaking changes in programming, it's not a physical thing where you can't go back. Start small, make tiny things, and over time you will learn more and more. Here's a nice guided path: unitycodemonkey.com/question.php?q=how-to-learn-unity Best of luck!
❤ Watch my FREE Complete Multiplayer Course ua-cam.com/video/7glCsF9fv3s/v-deo.html
💬 This was one of the most requested UGS tutorials, I hope you find it useful! Best of luck with your Multiplayer games!
✅ Learn more about Lobby and UGS on.unity.com/3XdKEd7
🌍 Get the Project Files unitycodemonkey.com/video.php?v=-KDlEBfCBiU
📝 Lobby Docs on.unity.com/3OtC0Du
🌍 Get my Complete Courses! ✅ unitycodemonkey.com/courses
👍 Learn to make awesome games step-by-step from start to finish.
🎮 Wishlist my Next Steam game! cmonkey.co/totalworldliberation
🔴 RELATED VIDEOS 🔴
COMPLETE Unity Multiplayer Tutorial (Netcode for Game Objects) ua-cam.com/video/3yuBOB3VrCk/v-deo.html
Multiplayer through FIREWALL with Relay! (Unity Gaming Services) ua-cam.com/video/msPNJ2cxWfw/v-deo.html
What is Unity Gaming Services? ua-cam.com/video/JwClCc2_zC8/v-deo.html
EASY Console! Run any Command! (Add Cheats, Set Gravity, Spawn Enemies Quantum Console Asset Review) ua-cam.com/video/bOf6CjpuSFs/v-deo.html
Simple Text Input Field Window in Unity (Submit Score, Name) ua-cam.com/video/4n6RT805rCc/v-deo.html
I found myself returning to this video often to refresh my memory when building my lobby I wrote down all the time stamps to the sections maybe some one can also use these...
1:54 install packages
2:06 setup services
3:08 script creation / service initialization
5:46 create lobby
8:18 search for lobbies
11:17 implement lobby heartbeat
13:22 add filters to search for lobby
16:55 join lobby by id
18:48 creating lobby options
20:12 join lobby by code
21:16 quick join lobby
23:48 print players
28:06 player creation refactoring
32:33 update game mode
37:30 handle update polling
39:56 updating player names
41:34 leaving lobbies
42:40 kicking players
44:40 transfer host
46:02 deleting lobbies
Thank you! I have referenced this video countless times while implementing Lobbies in my game. It would be great if these were added as chapters to the video.
Thanks
As someone who's been working with Unity professionally, you never cease to give really great reference to new services and quick implementation, keep up the hard work!
Thanks for the kind words! I'm glad you found the videos helpful!
when lobby host left the lobby, for example wifi disapears or game crashes, lobby disapears after 30s from the list, but players in lobby stays endefinetely with no warning that lobby no more exist. is there a way to change lobby owner when original owner is offline?
@@arvydazo4203I think host migration is in unity 6
I have returned to this video approximately 20 times over the last three weeks. It is amazing, giving only what we need and no confusion. I'm actually using what I learn to develop a unity package that incorporates everything here with steam, automatically setting player icons and names and such. Thank you very much for this tutorial, it would have taken me months without
I'm glad the video has helped you! Best of luck with your game, thanks!
Just a note in case some is facing the same issue. If you are using the editor to test (I am using parrellels sync package), the heartbeat might stop when you unfocus the editor window. You can change it in Edit -> Project Settings -> Player -> Resolution and Presentation -> Run In Background. Also the anonymous login will create the same id for both players when logging in by default. You can either clear the session tokens or use different profiles to get around it.
I just started game developing and it seems like all my ideas that I am excited about are all multiplayer, seems like I timed my start right, thank you for these valuable videos!
Heh nowadays making multiplayer games is easier than ever so that's great timing!
I remember when I added Multiplayer to my first Steam game, I had to build the entire Lobby Master Server infrastructure from scratch myself, it was very painful and very easily broken.
Really awesome that nowadays there are all these tools you can easily use!
@@CodeMonkeyUnity does a multiplayer game cost , or how much you need to spend to create a multiplayer game by your self?
@@ergicela4420 The lobby system in this tutorial is done with the base Unity system and is free as long as you don't use too much data (unless you have a lot of players this won't happen), then the hosting of the server is done by the player that is the host of the lobby. Because of this you don't need to run your own servers and the entire system is free to use. So no you don't have to pay to add multiplayer
Honestly Multiplayer is still difficult get some practice in, not years but just understanding.
If like me you're a newbie and get the error : "player is already a member of the lobby" while trying to join a lobby from different instances of the game, you have to find a way to differentiate the two players (host and client). One way is to change your authentication method like this :
private async void Start()
{
var options = new InitializationOptions();
options.SetProfile("Player" + Random.Range(0, 1000));
await UnityServices.InitializeAsync(options); //
Really appreciate this detailed explanation 👍
Was going to sleep, code monkey's notification came, so I am here ... Postponed sleep for next 52 minutes 😁
Heh don't worry, the video will still be here in the morning!
@@CodeMonkeyUnity 😅Yeah , But you can understand the passion for game Devs .
@@CodeMonkeyUnity अरे कुछ नहीं मंकी भाई यह सो गया था तुरंत ही मेरा रूममेट है ये
@@padamgupta6941 abe 🤣 ... Accha screenshot lagane ki wjh se dhundh liye tum... Bhkk...
Legend says that he still hasn’t slept. Been watching codemonkey nonstop ever since.
I'm working on the multiplayer version of my game, nearly finish this is coming at the right time :D Thanks a lot
Awesome video. I have come back to this several times while prototyping my own lobbies implementation. Would be super helpful if you included chapters!
when lobby host left the lobby, for example wifi disapears or game crashes, lobby disapears after 30s from the list, but players in lobby stays endefinetely with no warning that lobby no more exist. is there a way to change lobby owner when original owner is offline?
This is more than an amazing tutorial. thanks for sharing this. Looking forward to watching more multiplayer tutorials!
Awesome. 👍🏻😁
You made it look easy... which is the Best a Teacher can do.
I will try it on my future Prototype.
Thank you for making this video. 😄✌🏻
Yes Code Monkey, YES! I'm working on a VR artwork which uses multiplayer, but I had no idea how to setup the lobby, but with this everything is working just fine! Thank you for everything and good luck with the rest!
how dud you made so all the players would be spawned to gameplay scene ?
@@racistpixel1017 have to make it work with netcode for gameobject
Yeaasss! Will watch early tomorrow morning.
This video's thumbnail gave me a game idea: a superhero game with Code Monkey as the titular character.
Heh that would be fun!
Love your content. This is the best way to learn new concepts as opposed to reading documentation and thousands of lines of code in example projects. Your videos are extremely helpful and you saved my ass countless times. Thanks!!
I always appreciate your tutorials & this one's making all of this seem far easier than I'd have expected. Keep the great stuff coming!
Not sure what timestamp you're referring to, what two different variables? You mean lobbyName and maxPlayers? It's to avoid using magic numbers ua-cam.com/users/shortsCQ5xHgRZGQo
Sure, you can use a coroutine instead of a float timer. Personally I prefer float timers because I dislike the cumbersome structure that coroutines force you to use. You need a MonoBehaviour, need IEnumerator, need yield return, need StartCoroutine(); whereas with a float timer you just have a simple number. But that's just personal preference.
@@CodeMonkeyUnity Apologies. By the time I got to the end of the video it more or less made sense & I edited the comment, haha 😆. I was referring in particular to the lobby, hostLobby, and then joinedLobby variables. For the sake of "safety", I followed most of your instructions, though I did swap out the Update timers for coroutines as I'm just used to them. My head's swimming a bit as the last 20 minutes of the video really ramped things up a notch, but I was able to keep up well enough & everything looks good! I'll certainly be grabbing your project files to check for reference as I'd like to see how you implemented the UI functionality, particularly for kicking players & such. Thanks so much for all of the amazing tutorials (and I always use Codemonkey10 at checkout now, so many additional thanks for that, too). You rock! \m/(>.
Thanks for showcasing this package. As always a really useful tutorial! It gave me thoughts about if this is how channels are implemented in mmorpg's.
This is exactly what I needed, thank you!
Amazing tutorial. I followed along and got everything working. Thank you!
the Join player using Id didnt work is something wrong?
@@Hhuxx1 Hey! What's the error?
@@o2dyt Id didnt exist
Thanks so much for making this man, I’ve been waiting 😅
Yus! This is exactly what I needed! Any chance you could do Vivox next?
Yup it's on my list to research
@@CodeMonkeyUnity yus thanks you so much
Yes!!! UGS tutorials are amazing! Thank you so much! Can you please make one for Unity Game Server? I cannot find it anywhere on the net outside of docs and a video showing a practical example would be extraordinarily helpful, not just to me but to MANY others.
Yup Game Server Hosting (Multiplay) and Matchmaker are two other tools I want to research
This was gold! Literally just made my entire lobby system for my game just following along
Nice! Best of luck with your game!
@@CodeMonkeyUnity Thanks man! Appreciate it!
@@CodeMonkeyUnity Same ! Thanks a lot I'll definitely support you when my game generates more money !
how did you made so lobby players would be transfered to actual gameplay scene?AC
Im also trying to work that out, and have been through several days... when I download the project files they seem to be a bit broken, so its hard to figure out how the UI gameobjects should be constructed.
Yall, just a tip don't name your script "Lobby" since its a keyword it will give you head aches... :D
I knew i shouldn't name i Lobby but yet still my smooth brain did exactly wat i told it not to do..😂
You also can't name Players "Player" because Player already exists in the lobby package
Could you possibly make a tutorial on how to make the UI for the lobby and how to connect it to this? I've followed this tutorial but I'm not quite sure how to do that. The main problem I'm having is I'm not quite sure how to get the names of the players in the lobby, but I see you set it up to do that in your UI.
Regardless, thank you for making these tutorials for us!
Note that if the 30 seconds lifeapan of the lobbies bugs you, it can be changed via the UGS dashboard up to an hour (3600 seconds). Probably negligeable, but helps send less data, which is always good.
Oh that's interesting, I don't remember seeing that, must be a nice recent addition
@@CodeMonkeyUnity yas but lobby host leaves the loby, noone can connect to that lobby and it just stays there in the list with ghost players
I would love some insight in Steam intergration with Unity Multiplayer Networking
The Greatest Of all times ❤
Thanks for your efforts and
I hope you’ll see my comment
(Your biggest fan yasser)❤
I'm glad the video helped you!
This video was needed since i was thinking of implementing the same thing in a 2d game that im making, thanks!
Yes, finally a great tutorial on this!
Thanks, that was really helpful
Finally ...😍😍
You are awesome!
Super cool video. How did you manage to run 2 builds in Unity? Thanks!
They're not both inside Unity, only one is in Unity the other one is a standalone build
Its super lesson! Thanks! :)
If you are new to unity these tutorials will be somewhat challenging
, Because he's using his custom UI stuff instead of unity built in stuff. These tutorials can be simplified a lot.
What custom UI stuff? I'm not even using any UI for the most part of the tutorial, only made a custom demo for the end
@@CodeMonkeyUnity how can I switch to the game scene for everyone after creating the relay? Please respond this has been bugging me for the past several weeks
Really helpfully video and appreciate your work bro ❤
I have a question - as you said in this video, using netcode for game objects, relay and lobbies makes for a seamless multiplayer experience. What is the right video to start watching in order to do that? I don't really understand how they differ and how they work together.
Each of the videos focused on each tool.
This one is the lobby video
Here is the Relay unitycodemonkey.com/video.php?v=msPNJ2cxWfw
And NGO unitycodemonkey.com/video.php?v=3yuBOB3VrCk
i love your multiplayer tutorials
How to add search bar so that many players playing the game have option to search the name of any player and add him as a friend instead of lobby
How would I implement this into vr?
I'm getting a bug when I run my game in a standalone build that causes the player to never leave the lobby if I close the game while still inside it. I can force leave the lobby, but closing the game seems to leave the lobby open forever. Any experience with this bug or an idea on how to fix it?
UPDATE: I think calling delete lobby or remove player from lobby from OnApplicationQuit works, but only if you don't do it asynchronously (so no async/await in the call).
i have small issue. im using your lobby assets you provided. when player leaves lobby or relay. or shuts down game completely, he stays in the lobby and cant reconect. when im testing lobby always says it has two players, so the host and testing build. i also keep lobby on dontdesroyonload when moving to gameplay scene, just to keep lobby active for new players to join, but i dont think it makes this problem. also in dashboard in lobby i changed so if player is disconected for 10 seconds, he would be removed from looby, it was set on 2 minutes, and still it doesny work, players stays in the lobby no mater what.
thank you, you helped me a lot 😲🙂
Great tutorial very clear! Did you make a video on how to transition from the lobby scene like the one you created to the actual multiplayer gameplay scene?
You can just sync some Lobby data, set it to 0 by default then set it to 1 when you wnat to start the game, that's waht I did in my complete game ua-cam.com/video/7glCsF9fv3s/v-deo.html
Developer's Gem ❤
🤩 great tutorial
awesome tutorial!
I'm glad you liked it! Thanks!
Good afternoon!
In anticipation of the looby part of the "Learn Unity Multiplayer" video, I just finished the "Making a MULTIPLAYER Game? Join your Players with LOBBY!" video, a very clear and very informative video as usual. Thank you for the passage concerning the prices, I had already read it, but it is reassuring for a non-English speaker to have an additional interpretation.
I have many qustions :
a) when all players leave the lobby, we get a bunch of errors in the console:
- [Lobby]: LobbyNotFound, (16001). Message: lobby not found
- HttpException`1: HTTP/1.1 404 Not Found
How to manage them?
b) I didn't understand why we have 2 lobby variables (hostLobby and joinedLobby). We only have one lobby, don't we?
c) At 47:20, you have a using Unity.VisualScripting clause. This happened to me from time to time, and I got into the habit of uninstalling several packages installed by default by Unity: VisualScripting, Visual Studio Code Editor and JetBrains Rider Editor.
I have the impression (at 90%) that Visual Studio offers me fewer functions for autocompletion. I would like it to be automatic, but I admit that my first attempts were not convincing :)
Thank you very much for this video !
Connection with Codemonkey lost ... I hope you're doing well.
For (a) you would need to set the lobby to null in the catch section of the code, so that the Update function stops the heartbeat to an already deleted lobby.
For (b) you can probably modify the code to only use joinedLobby. I'm guessing CM uses two different variable names for teaching clarity.
I have no idea about (c). If you don't need that reference in your code, just delete the line. You should keep Visual Studio Code Editor package if you're using the VS IDE to write your code though, I think it's needed for proper integration.
Good luck!
@@davidwusoftdev Thanks!
Wooooo another multiplayer video!
i am getting this error while setting up the lobby system
Error CS0029 Cannot implicitly convert type 'Unity.Services.Lobbies.Models.Lobby' to 'Lobby'
Did you name your class Lobby?
@@CodeMonkeyUnity yep i named it the same took me a while to realize now everything works totally fine thanks the tutorial is really good
This great tutorial could really use chapters.
Thanks a ton!
I have a question about constructors and initialisers, like at 31:08, u have used curly brackets to pass in the arguments for createLobbyOptions, but on the other other, in some cases, just normal round brackets are used for passing in arguments. How does it exactly work? Thanks for the help!
It depends if the constructor has parameters or not. But regardless of whether it does or not you can always use curly brackets to set public fields
You are the best
How do you achieve to show so many features in a single video?
This is awesome!
Anyone else having an issue where the player class exist but also doesn't exist at the same time?
I didnt know unity had a high level lobby system like this
Is there any more detailed description on how you created the lobby UI? I have watched your other videos but still do not manage to replicate it.
Can someone help me with how I can create a player data of type int or bool instead of string? 26:37 Do I have to use string?
Data = new Dictionary()
@@Squid_Fat It didn't work it still asks for string for value
figured the issue but dont see a fix....When you press Authenticate without changing the name from Code Monkey, it will not authenticate nor let you go back...
Please tell that how can we make a functional search bar on which if we search then it will show the list of online multiplayers
And if we click on any player it will show option "add friend" if we click on add friend it will be added to our friends list
Do you have a database set up to store info of all players?
31:20 Lobbies Filter
My question is, I managed to connect, how can I switch to the game scene and how can I host it in the lobby via netcode? Or is it automatic?
Hi, have you found the solution?
update please
I can't even get past the intro before I get an error I can't find a resolution for:
"Cannot implicitly convert type 'Unity.Services.Lobbies.Models.Lobby' to 'Lobby'"
The code:
Lobby lobby = await LobbyService.Instance.CreateLobbyAsync(lobbyName, maxPlayers);
I even copied it directly from the website and still got this error. What am I doing wrong? I've added all the exact same "using" at the top of the script even.
Sounds like you already defined a class named Lobby in your project
@@CodeMonkeyUnity fuck... I did 😅 every time', the simple and easy babe is already taken and I spend days to try and figure out why it didn't when.
Thanks!
haha u saved me
Thanks~ very helpful ~
Can u Please Explain I can See QuickJoin Method On Lobbies Class And LobbyServices class as well whats Difference both?
Thank you for the video!!
I have realized one thing that happens sometimes.
It might have to do with the fact that most of the code here are async code that when I stop playmode (from testing), time and after the scene changes when exiting playmode - (aka is different to what it was before starting play mode)... usually this is fine as reloading the same scene by clicking in the scene from the project in the editor restores it to what it was before...
But I was wondering if this could happen for a build as well? because I had a few times where the camera was getting disabled for no particular reason when exiting playmode and this would be really bad if it happens in a build and remains that way...
question, @CodeMonkeyUnity, you mentioned that its better to create the game as one package, server, host and client... i am planning on making a mobile game... not sure if I should create the "Server" version first, then convert it to or switch type to Mobile after creating the server version... so the client can be mobile.. your thoughts? hoping to do a Dedicated server hosting for unity to host.
Loved the video! Just wanted to ask, why don't you like coroutines? I thought it was standard procedure to keep most of your logic inside coroutines and functions.
Personally I don't like the pattern they force you to use. You need to use a MonoBehaviour, you need to StartCorouting(), you need to make a function that return IEnumerator, you need yield return
I find that whole pattern to be needlessly convoluted.
But they work perfectly fine, so if you like them then by all means use them
@@CodeMonkeyUnity Those are definitely valid reasons. I guess I'm just more used to them now. Find it much easier to hold execution and sync with fixed updates in coroutines. Just wanted to know if I was missing something here.
I'm using ParrelSync to quickly test the game in another Unity Editor. But by doing this, the second player is assigned the same ID at the start. This means that I keep on getting the error "LobbyConflict, (16003). Message: player is already a member of the lobby." when trying to join. Is there any workaround?
You need to use a different name when Authenticating when running on the same machine, just like I added a input window to give each build a different name.
@@CodeMonkeyUnity Hello! I found a solution right after typing the comment but I think it got automatically deleted because I put a link in it.
I used authentication profiles to isolate my players. Here is my Start function:
private async void Start() {
var options = new InitializationOptions();
playerName = "Player_" + Random.Range(10, 99);
options.SetProfile(playerName);
await UnityServices.InitializeAsync(options);
This way, each player gets assigned an unique ID.
@@UnityDevJOY Just want to throw a quick shout out here, I ran into this exact issue on my end during my testing and this helped me resolve it!
Can you explain this? Where do you actually do this?@@CodeMonkeyUnity
Couple of minor changes I'd make - using multiple lobby variables is a bit confusing. You really just need one. Switching them back and forth isn't necessary since one client is going to be be a part of one lobby at a time. Also, logging into a lobby via code. I think for a tutorial it makes more sense to log in by lobby Id, because that's a value you can actually get. Only the host of the lobby gets access to the lobby's code.
What do you mean multiple Lobby variables? There's just one member variable which is set whenever a function changes it, you need to do that since the variable won't update by itself.
If you want to see it as part of a complete game I used this in my complete course ua-cam.com/video/7glCsF9fv3s/v-deo.html
do you have any video showing how to transfer data between host and guest and both of them getting notified on events? Usecase: guest changes its data and host gets notified about changes and viceversa.
I looked at the basic coroutine and couldn't figure out why you didn't like the pattern until I tried to make it async lmao
Lobby services with 10 gb is neat. Free authentication, remote config and cloud storage.
Relay services however can become quite costly**.
let's say your game is $15. 30% goes to steam, $5 for simplicity. Then you have your own take of $5. The rest $5 goes back into the game.
which means ($5 / $0.16) / 12 ≈ 2,6 years. After that you're paying it yourself to support your own games networking.
By then you require another monetization feature just to keep the game running. Or revert back to Direct IP which is troublesome for most players to set up.
Most of them don't even know how to access a router / modem let alone configure it for some game.
I'm ignoring bandwidth here, but that also is quite costly when you go above 150 gb of data.
Multiplayer is great, just not the costs that come with them.
** Sure there are caveats and this calculation is a worst case scenario 100% playtime. It still feels expensive. Perhaps my view on it is too extreme.
Your math is a bit confusing, you're assuming every single player will be online at the exact same time playing 24/7 for 2.6 years, that is an extreme scenario that doesn't really ever happen. Remember it's Concurrent users, not just Users.
As an example, my own game Battle Royale Tycoon, which was a decently successful release (for an indie dev) only had a single month above 50 CCUs with 75. So if the game was multiplayer it would have costed me $4 while it sold over $100,000
So to me the math seems really good. If you have thousands of CCUs then your game is a mega-hit which sold hundreds of thousands of copies and those players will not play 24/7 for 2 years.
@@CodeMonkeyUnity That makes a lot more sense. Like I mentioned with the '**' Worst scenario with 100% playtime. But you're right not everyone will play every day for 2 years long.
Thanks for explaining
when lobby host left the lobby, for example wifi disapears or game crashes, lobby disapears after 30s from the list, but players in lobby stays endefinetely with no warning that lobby no more exist. is there a way to change lobby owner when original owner is offline?
Is it possible to use this lobby setup, then on start, spin up a dedicated server? I setup matchmaking, but now I want to add the lobby service instead of waiting for random players to join.
Make a tutorial for netcode using Steamworks p2p also plz.
I would like that too!
Photon or Netcode what should I use?
Ur awesome man
My this question is out of this video----
Q- concept of making jungle marble blast game....how is work....?
Could you make any video for this....?
Thanks a lot for this great Tutorial.
I am having some trouble with connecting a UI to the code though, like you showed at the end. When trying to create the List of existing Lobbys I created a prefab for the list entrys but I can't figure out how to dynamically spawn elements of this prefab and also how to then fill it with the lobby name, maxplayers and so on. I tried taking a look at your project files but i can't figure it out.
Also for the UI, I saw you put everything in one Scene - I created multiple Scene for each "Window" - Which route would be considered "correct" according to Unity Guidelines? If your style is the proper way, do you have a Link to a tutorial on how you did that?
Again, Thanks a lot!
Hello, just using this right now, I added the team selection on my lobby screen but only the player themselves can edit their PlayerData, not even the host can, so how would you work around this?
Massive thanks for this multiplayer series, and super excited for the upcoming one, I hope you make more and more videos or even courses on multiplayer, DOTS, ECS... I'm sure they'll be very valuable. And I hope I can support with more sizeable donations in the future, being an indie dev making games with nothing released yet is kinda hard on my ressources 🥲
Thanks for the super thanks! Best of luck in your game dev journey!
I understand you mentioned how to make the players on team, but it would be great for you to show us. Im not that good of a coder and im lost most of the time. Anyway to make a video on selecting team both manual and random, adding friends, creating parties, thing like that. Seems like alot for me but it might not be that big of a task for you. Thanks even id you say no lol !!
im curious on how you made the chat and commands , a tutorial on that would be appreciated
It's a unity asset If I remember well. And he probably explained it in a previous video
See the previous video of the playlist
is it possible to spawn the players in the lobby in the same game with the character they picked using unity netcode?
When you join the lobby you can initiate the NGO connection right away, that's what I'm doing in my multiplayer game, video coming out next Monday
How do you change data for each player, like the avatars you've show in this video and sync it with other players? I've trying to make a team based lobby with no succeed, I have tried to change data of each slot for each player but it does not work, since only the player itself can change his own data and the host of the lobby can't change the data of other players.
Great Video! just want to know if we can customize the lobby code or not.. like if i want it to be for 5 characters only, something like that was present in photon i think!
No I don't think that's possible, it's auto-generated on Unity's side
We want to learn sign in google firebase. Everybody wait this thanks! Please next video do this!
Great tutorial. Quick question, How do you add bot in lobby? or do I add bot in game play?
You would probably only add that during gameplay. After you start the game if there are fewer than the max number of players spawn a bot for the remaining ones
How would i make it so the players in my lobby are moved to a round, preferably with netcode since i want to make a FPS
What font are you using?
It's the default TextMeshPro font, LiberationSans
@CodeMonkeyUnity wow thank you, i love how you reply to your comments ❤️ subscribed 😁
The Lobby deletes itself and doesn't migrate host after the host "unexpectedly" disconnects (simply turning off unity play) instead of just leaving the room. Is there a way around this?
I come with updates! when you poll a lobby for updates you can do special logic only when the lobby has changed. Every lobby has a version which changes whenever the lobby is updated. here's some sample code for checking for updates, put it inside the if statement for when the LobbyPollTimer < 0
Lobby oldLobby = joinedLobby;
joinedLobby = await LobbyService.Instance.GetLobbyAsync(joinedLobby.Id);
if (joinedLobby.Version != oldLobby.Version)
{
//your custom logic
}
I have some doubts,
how host is migrated if host has quit the game suddenly?
How Host is migarted without using migrateLobbyHost() by host as host lobby will be null hence no pingheartBeat would be called?
Can you help me with this simple problem? How do I get the player data saved in the lobby, such as name and loadout, in the game when I actually run it? For example displaying the users name to other players? I know it's probably simple but an explanation would be awesome.
Store it in a variable locally on the lobby owner, have that lobby owner start hosting the game, wait for all to be connected, send a ClientRPC to send that data to all clients
Or you don't even need the host to send anything, just store in a local variable for each connected player since they know the lobby state
@@CodeMonkeyUnity I'm so sorry could you explain it in more detail? I guess I don't entirely get how the client rpcs work here, like save the variable in the lobby script or the player script? Also how do I connect the PlayerId from the lobby to the networkmanager client id? Are they the same?
Can you please tell me how to add search button in it
I covered the filters at 13:22
No I just ask that how add search bar instead of lobby like I have many players playing online game and one of them want to add another as a friend and he will search his name on the search bar and then add him as a friend
Should you leave the lobby open during a co-op game say a simple co-op ARPG/Co-op hack and slash game?
Depends on what you want to do, if you want to enable something like host migration then yes leave the lobby open, if not close it
I want to make a great game but I am wary of how much, complex and overbearing trying to learn what's required will be. All Unity basics, csharp+ whatever it's called, all the computer stuff I'm not tech savvy with, if I mess 1 pivotal super important thing and can't undo it, what if loading tests are way too long, what more costs I might need that Idk rn etc.
lol don't worry about sprinting before you can crawl. I've only started learning recently and it is extremely time consuming and tedious BUT I can honestly say its worth every second. If your passionate about something never let something that might not even happen or be a problem you face hold you back, just go
Don't worry, you can always undo everything, if you write some code and it gives an error, you can always find and fix the error, there's no permanent breaking changes in programming, it's not a physical thing where you can't go back.
Start small, make tiny things, and over time you will learn more and more.
Here's a nice guided path: unitycodemonkey.com/question.php?q=how-to-learn-unity
Best of luck!