How To Make A Multiplayer Game In Unity 2021.1 - Boss Room Sample

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
okay so hello and come back to another unity multiplayer tutorial in today's video we'll be having a look through the bus room sample project that has just been released i'll be showing you how to get access to the project and set it up inside of unity so that you can build and play the game for yourself we'll then have a dive into the project itself to look at how they set things up and how some of the code works and then of course if there are any features systems mechanics that you see or come up with that you think would be a good topic for a tutorial be sure to let me know down below and i'll see if i can get around to it that's it for now so let's get started as always the links to the pages that i'll be showing will be down in the description below so here we are on the page about the boss room sample project and we've actually been here before in my first video about the new multiplayer solution we visited this page it told us what was coming and it said here we could save the date but now it's able to be downloaded if you want to you can have a read through this yourself as i said it'll be linked down below and like it says down here at the bottom it's an educational template so you can go into the source code and have a look through and do whatever you want with it and it also tells you here it is early access so this project itself will be evolved over time like it says here it's going to continue to be developed and supported because as new versions of the multiplayer solution come out they're going to update the game to match that so that the educational aspect of this stays intact it doesn't get outdated now if we scroll back up we have this button over here to take us to the getting started guide which will take you to this page over here which is on the documentation so this page explains how to get started with the boss room sample so if you prefer following text tutorials then this is here for you but if you want to follow along with me in this video we can scroll down here and we can get the project files from github so let's hit latest releases and it'll take you to this page over here the latest version right now is 0.1.0 so to download it we can scroll to the bottom and grab the zip but before i do that you'll see here there are some known issues so if you do have a problem and it's on here then no need to worry they're already aware of it but if you notice something else that isn't on here i'm sure they'd like you to report it on github or to mention it in their discord server so that they can sort it out so go ahead download the zip here once it's downloaded make sure to unzip it so i'm going to extract all to this location so once it's done you can delete the zip file and you're left with the bus room project folder now i'd recommend moving this somewhere else out of your downloads probably to where you keep all your unity projects so i'm going to delete mine here because i already have it in my unity projects folder if you then open up the unity hub hit add and navigate to where your unity projects are find the bus room project and to add it you need to go in one layer to here community multiplayer samples and hit select folder now in my case i already have it here so i can dismiss this warning and this uses 2020.3 so unity 2020.3 and i've got patch 1f1 it really doesn't matter about the patch just make sure you're on 2020.3 once that's done you can click this to open up the project once unity has opened you may be just in an empty scene so go to bus room scenes and make sure you're in the startup scene once you're there you can go file build settings build and go make a builds folder so i've already done this i've made in the same layer as assets documentation library i've made a builds folder and one inside of there called test build and this is where my build will happen and once you've done that you can then hit select folder and it will build it to there so once it's built you can run it as many times as you want i think the game goes up to eight players though it might go past that but all i know is it definitely goes up to eight now i'm going to run with four players here the top left is going to be the host so i'll hit start confirm allow access to the firewall and then on all these others i'll hit join join and join so now by clicking the different characters we can actually go through who we want to play so i am player one over here and i can click whichever character i want to play so we've got the kind of warrior archer mage road and then warrior archer mage rogue again and we can do on all the different players so maybe over here i want to be a warrior over here i'll be an archer over here i'll be a mage and over here i'll be a rogue let's say and then we can ready them up so ready ready and you see all the feedback happening across the different players so already up and once everybody is ready the game will start so the controls is left click to move and target enemies right click to do your attack and then you've got different abilities down at the bottom right based on which class you're playing so let's hit okay over here so here we all are now at the top left i'm the warrior guy so i'm going to run around and as you see here it's got synced movement on all the different clients we've got health bars names obviously our different abilities at the bottom right and let's say i go over here i've got the first enemy i've attacked i can start clicking on him to attack him we've got the synced animations from attacking and moving and we've also got a moats over here so i can wave and you'll see on all the different players my character is waving and i can move over here and start controlling the wizard mage so i can go down here and try and find another enemy i'll bring him up here and i can now turn around and start attacking him with my ranged attack like this there's obviously plenty of other cool stuff here like we've also got the heal spell you saw i just healed myself if i go on the road down here you can see i can use my invisibility spell once it happens i get this cloak of pink mist and when i run past enemies they actually don't attack me because they don't see me so i could just keep going and playing the game to try and finish it but i'm sure quite a lot of you probably want to play it for yourself and it's also quite difficult to juggle four players just on my own so i think i'll leave the rest for you guys and we'll have a look into the project itself now so i would recommend having a look through the project and the code for yourself it might be quite daunting at first because you look into one script and that ties to another script you've got all these references and you don't know what anything does at the start so it might take you a while to familiarize yourself with the project but over time it gets easier and easier and everything starts making sense so here in the startup scene we have various game objects that will exist throughout the lifetime of the game such as the settings panel where we can control the audio of the game if i was to hit play this will persist through from the startup to the main menu scene i can control the volume from here we also have the game data source which acts as a mini database as such for scriptable objects and then we also have let's say the network manager with all the prefabs that will be instantiated over the network and the player prefab is marked here as well as scenes that are registered to be transferred to over the network we scroll down a bit i'm pretty sure most of these settings are default apart from connection approval is enabled just like in the previous tutorial i made on connection approval we also have the game hub and if we go into here it has free scripts one is a general net portal and then a client version a server version to separate out some of the logic so inside of here it will explain it's a general purpose entry point for the game and it also has network messages so if we scroll down there's quite a bit here to wrap your head around but we basically have a way to start hosting that's their logic for when you start hosting and if we go down here we have various messages so we can send over the network our own messages like connect result and scene changed and then we can receive them and if it's on the server or the client we can do whatever we want they also use the naming convention here c2s for client to server and s2c for server to client so as an example we have the connection approval on the server so let's go over to the server net portal and if i scroll down somewhere in here we have the approval check just like in my previous tutorial here's the logic for the approval check and you'll see over here for example they say s2c connect result it's the method we were just looking at it's a message that is sent from the server to the client sending them a connection result and they have this enum here so connect status dot success and that lets the client know that the connection was successful now in my tutorial i just sent across as the connection data just a password and that was it but in their case they send across an object which means you can actually fit in more data there so for example they send across the player's name that's a good use of it we can actually tell the server whilst connecting what we want to be called rather than waiting to connect and then saying what we want to be called so you can do that all in one go and as another example if we go back into unity and open up the client script where they have that logic we can scroll down and find where they connect as a client and if we look down here for example connect client we start filling in this connection payload here so if i put it onto multiple lines to make this easier to read we have the three separate things here that they send so they send a client guide which is just a basically a random string um then we have over here the client scene which is which scene they are currently in and then the player name is whatever name they have when they go into the game they then convert this object into bytes and then with the bytes they set it as the connection data just like i did in the previous tutorial and then we start the client which will send that to the server so now let's have a look at the character selection so there's obviously a lot of code here and i'll just be giving a quick overview of how some of it works so let's say i wanted to click on this player one let's see actually what happens so if we open up the ui canvas we've got these player seats which are just the different characters if you go in the scene you can see that here so player seat zero we've got the script on it to select the player seat and if i scroll down in here this is the event sorry the method that's called by the button so we'll go back into unity open this up open up a bit more there is a button component here and when we click this button it calls unclipped which is here and this will then call with a seat index keep in mind the c index is just which character it is so this is player zero one two three four and so on so this would say if i clicked on the first character on player clicked seat zero and inside of here it actually then calls an rpc now i haven't covered rpcs yet but what rpcs are are methods that you can call either on the client to then run on the server or the server can call one to run on clients so in this case it's a server rpc what that means is a client is calling this method but it will end up running on the server side so this rpc which will send a message to the server will send through a you log which is the client id so this is who it is that's actually uh trying to change character and then over here the seat index which is which character they're changing to and then bull locked in is are they locked in yet so are they just clicking a character to preview them are they actually locking in their selection now if i hit f12 and have a look into this method you'll see over here when this happens it will then on the server side uh invoke an event saying that the client has changed a seat so with this if we want we can go deeper we can right click on the on client change see event and see where it's used so over in the server side for this we can see it subscribe to here and it calls this method so when a client changes character the server will run this code it'll say find this player and make sure they exist if they don't then throw an exception and then make sure that we're still locking in we're still in the lobby if the lobby is closed it means we can't change characters anymore that's already done then we go and say okay go through all the players and see if anyone else has the same character or if they're locked in no sorry it's and here so it'll make sure that the character you're on uh is not locked in so you can look at character two while someone else is looking at character two but if someone else locks in you won't be able to lock in as that character and then it will update the data here and we'll have a look at this lobby players network list in a minute so it'll set your id player name number and various other things here whether you're locked in or not and then once you lock in it will go through and make sure that if someone else is also looking at the character you've just locked in it will effectively kick them off it like it says here it will help clients visually keep track of who's in what seat will kick out any other players that were also in that seat now if we have a look at this lobby players list over here it is a networked list and what that allows it to do is when it updates on the server side all the other clients will then see that and then what we can do here is right click on this go to references and on the client side we see here they subscribe to the event for when this list updates on the list changed we'll go there and we'll say what happens when the list is changed which gets updated whenever any player selects selects a different character so we look over here and this is where it updates all of the user interface on the client side and of course you can have a look through here and see how it does all that for example update character selection and it starts filling in game objects info boxes and various other things like that so as you can see there is a lot of code and i've barely scratched the surface i didn't want this video to be over an hour long so i tried to keep it simple and i hope the bits i did explain make sense to you and that you can go through the rest with the same kind of method and try and understand understand how it all works like i said at the start if there are any features systems mechanics that look interesting to you and that you want me to make my own individual tutorials on building from scratch then just let me know down below and i'll try and get around to as many as i can but yeah that's it for this video so if you enjoyed or found it useful then be sure to leave a like and subscribe that would help out a lot share it with anyone that you think would find it useful thanks as always for watching and i'll see you in the next one goodbye but of course before i go i've got to thank my patreon special thanks to francisco lira liz kimber beard or die captain garfield david mcdermott evan maxie joe sletter casey katinka mom lauren simpson malvin hall mike troupe wreck san marcos ulfgrim andrew williams chris diplock theory and dario if anyone else is able to help support the channel monetarily the link to my patreon is down below if not there are also links down below to other social media such as twitch twitter and discord if you could help us out by following on any of those or checking any of those out that'd be greatly appreciated thanks again for watching and i'll see you in the next one goodbye
Info
Channel: Dapper Dino
Views: 37,430
Rating: undefined out of 5
Keywords: unity multiplayer, unity multiplayer tutorial, unity multiplayer 2020, unity multiplayer 2021, how to make a multiplayer game, unity multiplayer game tutorial, unity networking, multiplayer networking, unity multiplayer game development, how to make a multiplayer game in unity, new unity multiplayer, new unity multiplayer system, boss room, boss room sample, sample project
Id: CmwZPYV-a1o
Channel Id: undefined
Length: 14min 50sec (890 seconds)
Published: Thu Apr 08 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.