Hosting, Finding and Joining Sessions | 04 | Multiplayer Battle Royale | Tutorial | Unreal Engine 5

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey guys quick heads up before I start the video the link down below takes you to my patreon where you can download the project files for this video also get access to my premium tutorials and in-depth courses where we build games together from start to finish check out my patreon below gain direct access to years of experience so that you can start working on your dream game tomorrow hello guys and welcome back to a new part of the multiplayer Bean Battle Royale Series so in the last video we set up our hosting and joining widgets so in our main manual widget folder here we made a create game for hosting a game widget we made a server browser widget and then a serve browser item widget with which you can actually join the sessions uh so in this video we're going to continue on this and we are actually going to be coding these widgets so that you can connect players to each other using the default online subsystem so uh before we do that I just want to teleport to the main menu level and hit play to show you guys so we could uh we already C CED the functionality to click create game here we get the create game screen like this so we got the option to fill in an amount of players we can click on l or not and then create game and then we can click back and then the find game button takes us to the server browser where we have the option to refresh the server browser it's then going to have to show us the items that we find so the available sessions and then we want a little join button here to join them and then we can go back and we can exit the game all right so let's go ahead and get started with this but before we get started with this I want to explain something to you guys about what sessions actually are so for that we are going to go over to the internet to the Unreal Engine documentation all right so guys if you go to the docs unrealengine.com then you'll find yourself over here and then I want you guys to go to the programming and scripting section and then all all the way in the bottom of programming and scripting we will find The Online subsystem category so I want you guys to open up one and then in a new tab so if we go into a new tab then I want you guys to open something here as well so if we close these up then we can find ourselves the make interactive experiences Tab and then inside of this tab is the most valuable data that you can read about Unreal Engine so I really am going to recommend you guys right now to actually go ahead and read the Unreal Engine documentation properly when you are starting out with unreal or whether you are new um the the unra engine documentation is by far the best source of knowledge out there on the internet when it comes to unra engine it's better than any tutorial you will find and it will cover everything that the engine has to offer plenty of times I get people asking me questions how do you do this how do you do that keep in mind all of this information is right here inside of the documentation you just got to go ahead head over and actually take a proper look at it uh some of you might not even have read the documentation ever and just started using Unreal by watching ing tutorials which is fine but in here are all the answers to your questions so um the gameplay framework is one of the most important ones that you guys uh have to read at some point in here we start to understand all of the relationships between the core classes of honoral engine so what I mean by that is the relationships between the game modes the pawn class so use the character the player controller the hood the game State and the player state so all that super valuable data is all in here you'll understand how the whole framework works together and for working on R engine it is very important that you start to understand these individual classes because understanding these classes allows you to know what to code where okay not to go too far off of of the point from this video um so we're going to go ahead and click open the network and multiplayer part this is where onra engine actually talks about replication and the multiplayer side of things so here we are going to be clicking on the networking overview and then I want to scroll down a little bit which takes us to the client server model part uh and this is where I want to take you guys to explain a little bit of how under engine works and uh what we are going to be doing right now when setting up the sessions to actually be able to travel people from the main menu into the Battle Royale Lobby and how all of that actually works inside of unal engine so for that first I'm going to take you guys here to the Battle Royale level uh and what we're going to do here is that um or actually I'm going to take you guys to my testing level that we had previously set up and in here we already have player start and I just want to show you guys a couple of things before we actually get to making those widgets here so uh very first thing that I want to show you guys is that when in our engine we can just hit play here we can click on these dots here click on new editor pi to get separate windows so now we get a separate window that we can skill just like that and then if we click here then go to net mode then we see a couple of options of how we want to play the game so we can play it in Standalone which basically means that we play it as single player we can also play it as a listen server and we can play it as a client so if we click on play as listen server then type in two players and hit new editor Pi then it gives us these two windows I can put one to the right one to the left and then it will show us that this is the server and this is the client so basically why is this important and why am i showing you guys this well this is important to understand what sessions are and how players are actually connected when we are in the editor onor engine uses the default subsystem uh and what is a subsystem well a subsystem has uh many different functionalities that can get a player uh hooked up to something like sessions so sessions is the most important part out of a subsystem and by default when we play in the editor like this our engine does this all behind the scenes for us so it connects this right window this window to this window on the left by setting up a session behind the scenes that we don't see happening and that is basically how we get this guy connected to this little guy so um to to go over here to the website then in this case I want to explain the following so if we head over to the Online subsystem category here then we can see that an online subsystem is an a provide an interface with a lot of common functionality and features for online services and what are these online services well think about steam think about Xbox Live epic online services Facebook and so on all of these platforms have different functionality but they got a lot of functionality in common such as when you have your game on Steam you guys might be familiar with achievements also you guys are familiar with your friends your leaderboards being able to purchase items from a store and uh and perhaps uh user Cloud so that you can save local save files for the game in the users Cloud so um so that the progress of a player does not get lost then we also see the last and most important thing also most important to this video which is sessions so what are sessions when it comes to a subsystem to an online subsystem well as it says over here a session is responsible for creating destroying and managing online game sessions also includes searching for sessions and matchmaking systems so uh this is basically how we can get players connected to each other by using sessions so now I'm going to quickly explain some little overhead here to explain what unro engine is and how we handle multiplayer in un engine so it's very general so uh over here I'm going to make a little folder and call it like um explanation uh explanation and inside of here I'm just going to quickly right click and make ourselves an actor class and call it multiplayer explained and if we open this up I'm literally using this actor right now uh to Showcase some information about multiplayer in our engine so it's it's more like a whiteboard in this case so first of all when we think about multiplayer then what do we think about well we think about shooting running around everybody seeing the same thing in sync playing over the internet right so multiplayer Works different in different game engines and in unal engine it basically exists out of two things that's what I always like to tell people so uh in the core multiplayer works the same in any type of game engine but in honoral engine it works the way that I'm about to explain it so when we get multiplayer then we take a look at multiplayer in Unreal Engine and it exists out of two things and these things are sessions which is the art of connecting players to each other and then next to sessions we also have something called replication and this are the two different parts that it exist out of so sessions have nothing to do with replication and replication has not much to do with sessions uh but replication occurs in a session so first you need to somehow get your players from a main menu into a match or like a Lobby or a gameplay level uh and that is what the session handles and that handles via the online subsystem so sessions work via an online subsystem um and by default the engine has a subsystem uh which it uses here in the editor to create the session to connect your one client to your other client which is the default online subsystem which we can also read about over here inside of the documentation so uh if we scroll down here we can see that there is a base module for an online subsystem uh and what this model is is that it is the we call it the default subsystem also known as the N subsystem so what does it do create session destroy session and managing online game sessions um so how does that work actually how do we get to those session notes to uh be able to create destroy and manage online game sessions well it as I said it is install by default in the engine and it is used right here whenever you do this it on engine does this behind the scenes and the reason that we know that it does this behind the scenes is if we go over to this networking tab over here and then uh we can scroll down from the networking overview a bit then we get to the category over here where we see the different network modes and server types so uh now we kind of need to have a little understanding of the differ server types and how that works in onal engine so to explain that we're going to put one little category in between here where I'd quickly want to go over different types of servers when it comes to multiplayer games so for onra engine we have sessions and replication but what is above this and why is it called a listen server over here but in in the documentation here we see that the listen server is called here we see it is called the client server model so how does that all work and how does this all mix together well when it comes to multiplayer most of you guys have probably heard about something called a dedicated server and when we talk about a dedicated server most people get extremely excited because it uh to them it means World of Warcraft RuneScape and being able to connect and disconnect to a multiplayer game whenever you feel like it then we got another famous model which is called the Cent server model this model is uh extremely famous but a little less popular uh when it comes to programmers in my opinion because one player is the host and the other players are the client so the so you are the client to the server um and in this model uh we got that famous problem that when the host who is also a player disconnects all other players connected to the server will disconnect as well and the game will simply stop we saw that in like call Dy and such and then the last Model that we have here is peer to peer and peerto peer is a model in which everybody is a little bit of the host so when uh people disconnect the session will still uh exist as long as at least one player is there and for a dedicated server then it is not a player who is the host but it is actually a server dedicated to hosting uh and that server exists on a virtual machine typically somewhere in an AWS server farm and and that is where the session would then exist so on the host on the server is where we basically create a session and then the session is the time that we play together in multiplayer so when I create a session then it will exist for a period of time let's say an hour because I'm playing it for an hour and then all my other friends can join to me and they will become clients to my server that's in case of the server uh that's in case of the client server model and then since I am the host of the match and they are the clients then I as the host am the one responsible for serving them the data to keep us all in sync now keeping players in sync in our engine is called replication we want to replicate one instance of the game to the other instance of the game to the other instance of the game to however many instances there exist and how many instances exist is equal to the amount of players that are in the session um so why what's the difference between all these three well first of all dedicated servers are not free they're hard to set up why most of the times uh dedicated servers are used for way more players so dedicated servers are intended for like U 60 to 120 players which means they need to be optimized which means they need to be built in C++ and not blueprints um besides that uh we got client server model this is a simpler model where you just cach your game the way that we do in unreal uh one player becomes the host other players connect uh and then we got peer-to-peer this is easier there's way more documentation to find about client server model the reason that there's more documentation is because typically you play it with like six to 12 people or four people in a co-op horror game for example um so yeah there's more documentation to find because it is played with such low amount of players it can also easily be done in blueprints does not need to be highly optimized nor safe so that's why client server model uh has more data available on the internet to it and peer-to-peer is not available in Unreal Engine but it is in other engin such as Unity it is not very safe everybody is the host uh so everybody could manipulate the files and then cheat in essence but uh yeah that's peerto peer so this one is typically not free unless you got your own server Farm sitting in your house this one is free and this one is free because your players provide the server they are the server then some uh pros and cons the dedicated server it's uh the safest it does not exist as a file on the client so it does not exist on the local computer of the player uh the client server model and the peer-to-peer server model are both not safe so if you're making a game and you're running it as a listen server and you're coding it like that then no matter what you do when it comes to Authority and coding it in a safe manner it is simply not safe because um uh when you have your game so your x file of the game then uh you download your game from let's say steam the client would get the the game version so it would get the do XA uh which is uh the game client so it's the it's the do X game client this is what you download off of steam now the host has this one and uh the people that connect they all have the same game same goes for peer-to-peer everybody has the same game so because this game exists on your local computer that means that uh people can open it up if they are expert hackers and then they can basically uh manipulate the files inside of here and they can make themselves fly in short uh and here everybody is a bit of the host so everything could get all messed up and here uh here you have everybody is a client so it's somewhat safe so the clients cannot really do much CU then the server would correct them and would override their cheats but since one of the players is also the host here then uh it is not safe at all because the host can simply hack the game and then the host can be the cheater and that's what you would see back in the day in Call of Duty lobbies you would see that only the host of the match was able to fly have infinite bullets to shoot and such so these models not safe but they are efficient and free and stuff and then for the dedicated server then you typically you download your game from Steam but then there is another XA file which is only dedicated to being the server which gets uploaded to some kind of virtual machine server Farm some in the world which is not accessible for the clients and therefore if you have code here then the dedicated server is the only actual model that can be safe and that is also the reason why you see actual games like pubg and Call of Duty and uh let's say Counter Strike they all run on dedicated servers for those purposes also the hardware part uh clients can have all different kinds of Hardware somebody can run it on a laptop that is about to explode but a dedicated server then the server can uh be the same for everybody obviously the clients have different network connectivity so the clients could have a good internet or shitty internet but that goes for this model and this model as well okay so now that we know these three different models what is available for us in unreal well in unreal we got the client server model available for us and we got the dedicated server model available for us and the client server model is also called the listen server so the the listen server here is basically um yeah you as the client are listening to the server you're getting commands from the server and making sure that you get its replication to keep yourself in sync and that multiplayer properly works so that's the model that we see when we click over here listen server now if you want to test as a dedicated server then you can simply test as client only uh but you can also test as client only when testing for client server model to ensure that you play you you properly test how clients experience your game when you test this way so why am I explaining all of this to you well with the client server model somebody becomes the host the other becomes the server we see that when we click here with two players so when we're in a level and we hit play then we see them connecting we see that this gu is the server and this guy is the client and then the way that they connect to each other is by using those sessions so how do how do those sessions actually work well um if we right click here and if we then type in session then we can scroll down a little bit and we get to the category called online and under online we see session and there we see the notes that are corresponding to what the functionality explained to us over here uh for creating destroying and managing um so in unreal if we type in session then we basically if we scroll down we see that create we see that finding we see the joining and we see the destroying and those are the notes that ourang engine uses behind the scenes when you click play playing as a listener server for your net mode so let's get these notes into the scene so we got create session then if we type it in again then we got finding of sessions then if we type it in again then we got joining of sessions and then if we type it in once more we got destroying of sessions so what happens when you actually click pay unal spins up one guy as the host who creates a session and the other guys are clients who are joining this session and that's what it locally does and that's what we're going to be doing here as well but when doing this the session only exists on your local network so don't expect that when you use these notes the default subsystem that when you package the game and send it to your friend who is located in Canada when you are located in England don't expect that you can automatically connect to each other like Wizards that's not how it works uh when using this then the session will only exist on your local network so if you and another laptop of yours or your brother for example uh is on the same Wi-Fi or on the same cable network uh in your house using the same IP address then you will be able to find these sessions and to join these sessions that are created uh because they will only exist there now you can use these nodes for online but that would mean that you would have to expose your IP address and your router stuff and your ports for everybody in the world to join now obviously you don't want to do that that's not very safe so because of that we use these other parties such as Steam or we use something called EOS the Epic online subsystem which is from epic games themselves for the epic games marketplace now when talking about these subsystems so these are no longer the default ones that these are the solution to being able to host multiplayer games when working with the client server model so if you want to host free multiplayer games on Steam for example then that's the way to go now at that point you're going to have have to replace these nodes with uh other nodes that are compatible with these subsystems and on the marketplace there are a lot of plugins for both Steam and EOS that provide the online subsystem specifically for steam in which you will then be able to replace the create session Noe with creating a steam session and the find session node with finding steam session uh and basically that way you can then host sessions that no longer run over your home network but run over the steam Network and when you do that uh you will have the ability to join people overseas and all over the world and connect them together in your multiplayer game so that is the session part that is basically one part of Unreal Engine uh and obviously you can also have dedicated servers that way you can avoid steam you can avoid the client server model and if you host dedicated servers then you just need to make a server browser in which you expose servers um to the players so with IP addresses of each individual dedicated server you can then have people directly join here without going over the Steam subsystem and then you can avoid this as well so dedicated servers are the only exit way to avoid these notes basically and to avoid having to do all of this so um that was my little introduction here to what sessions are because uh it's important to understand how this works before we start actually setting up these widgets here uh and then replication like I said replication is the art of just replic a your multiplayer game if we take a look here in on engine then uh one more little thing for the listen server It also says here the game is running a server hosting a network multiplayer session there we there we see it uh here in the documentation explaining that this is what it does behind the scenes and then it says it accepts connections from remote clients so those are the other players playing and that's local players directly on the server well the only local player that is directly on the server is the the host the server itself so it's one guy or girl uh this mode is often used for casual co co cooperative and competitive multiplayer well as I explained before I do not recommend using this model for competitive multiplayer I recommend it uh for uh funny uh uh non-important multiplayer games such as Co-op multiplayer uh horror games like fosmo phobia for example those are perfect to run on this model when it comes to Counter Strike and Esports it's a nogo um all right and then the other part of multiplayer is replication in our engine what makes up multiplayer on engine we know that it's not peer-to-peer it's these two guys it's the sessions and it's replication so uh replication what is that well if you head over to arm engine here you see networking and multiplayer if you click that tab it is under making interactive experiences they got the nicest description for us over here which is modern multiplayer experiences require synchronizing vast amount of data between large numbers of clients spread around the world what data you send and how you send it is extremely important to providing a compelling experience to users since it can drastically affect how your platform performs and feels in onal engine replication is the name of for the process of synchronizing data and procedure calls between clients and ser the replication system provides a high level abstraction along with lowlevel customization to make it easier to deal with all the various situations you might encounter when creating a mult a project designed for multiple simultaneous users AKA multiplayer so that is what replication is and replication n engine is handled in two ways we got rpcs remote procedure calls which is the client communicating with the server back and forward and besides that we got replicated variables which is the act of getting data and values sent over the internet to each other uh so that everybody can be in sync so we're not going to talk about this in this video but we'll talk about it later we're now going to focus on this and how are we actually going to set it up if you guys are interested I'm also going to basically uh be setting this session stuff up um uh for steam so I actually want to implement steam that you guys know how to set that up but for now we're just going to be using the default nodes because uh you need these regardless if you use steam or not these this one and this one will maintain the same so let's go ahead and set it all up let's click on save all sorry for the extremely long side explanation but you guys do need to know it when making this multiplayer game so we're going to head over to the main menu in which we have our widgets here our session widgets and first of all we're going to create uh set up this create game widget so if we open it up then we have the create widget here so the first thing that we're going to need to do is that we're going to click on this um uh on this max player box and we already set it to be a nice variable name in the last video so we're going to click on text changed next up we're going to click the Lum and we're going to scroll down and click on on state changed and the last one is then the create game button itself so the on click event so this is how we create a session so when we click on create we just instantly want to create it so that's what we're going to handle first this onclicked event so when we drag off of here as we just saw in the explanation note we need that function called create session and the function asks for uh a couple of inputs a player controller public connections and whether or not we want to use lwn so the player controller is the owning player of the widget so whoever made the widget is that player controller but since we are in single player and in the main menu we can also simply type in get player controller and then if we are at player index zero that is us who locally exist on our computer we are the only player controller that currently exists when we are located inside of the main menu level which is offline level so you can use either this one or this one so for Simplicity sake we're just plugging get player controller in here Theo connections is how many players you want to host a session for make sure that this is at least one player right because otherwise you can't host a session but um actually make it two at minimum because it's multiplayer so you want to allow at least two players so the public connections we're going to promote it to variable and call it max players and that's it and then the use l we're going to promote it to variable as well and we're going to say use use l question mark So now that we got these two variables we hit compile and save and then it's very important that if players do not fill in this data or this data and simply hit create that they also create a proper session so we're going to handle that first so to do that we need to ensure that the max players over here has a default value of what I just explained two and that use l can be off by default so in this case that you just hit create then we basically want to set it up like that and then um and then what happens on the success note well when you click on creating a session you then want to exit the main menu and you want to head over to the level where you actually want to host the game which in our case is the Battle Royale uncore level so I'm going to right uh double click and then control copy this name and then off of the success note here we're going to type in open level by name and in here we're we're going to uh paste our name and then uh so what happens now at this point we are creating a session and then opening the level to get the host into the level so now the host exist inside of this level with the session but then there's one important thing when it comes to multiplayer and that is when we click up here we just explained what the listen server is so this level needs to be a listen level and for that in our engine in the options we need to type in listen so that we make a listen server check out cact center right now steam in Early Access it's a very fun multiplayer video game cheaper than the Starbucks coffee so if you want to have a good time with your friends or strangers click that link down below and I appreciate every single one of you and enjoy the rest of the video [Music] bye so uh that's basically it now we already created a correct session so if we go ahead over to the main menu and then ensure that we have one player in stand alone cuz keep in mind when you're in the main menu you never want to test with two players as a listen server you don't want to connect players here that would never happen in your actual game either uh you only want to connect players here so when testing for multiplayer you want to test directly in the level unless you want to test your whole session logic of to see if it actually works to get players from this level to that level Etc but otherwise you would just test your replication so you would not be testing the whole session stuff no when making your multiplayer you will be testing the replication side of stuff and to test replication we need to be in a connected session so you would just immediately go you would just directly go into a level and then click on here and click on play as listen server to players but now that we're in the main menu we're going to see if we can actually travel to this testing uh or we can see if we can actually travel to the Battle Royale level here so we're just going to hit P got one player and then we're going to hit create and we're just simply going to click the button cuz we haven't coded these two ones so hit create and there we go so now we are in the level but we're stuck in the floor so then we can quickly take a look here why are we stuck in the floor well we have not set up any player starts here nor a game mode so let's do that first so we're going to go up to here to basic and then we're going to get ourselves some player starts perfect and then we're going to assign our game mode so it is the core game mode for now and that contains the character so we can try it once more we go into the main menu level and we hit play we click on Create and we simply click on create game and there we go we now spawn into this level here with our character hit close and that's that now I immediately noticed that I we cannot control the character how come that we cannot control the character well our our focus is not corrected yet so in the uh widgets here we set for the main menu I believe when we take a look at the uh main menu player controller we set the input modes to focus the UI only so when we go over into our core and then displayer controller then we need to ensure that this player controller only be G play since this is the core gameplay player controller we need to always set the input mode uh to game only in this case for the player controller which is ourself so if we tried once more then we go into the main menu here we hit play we click create game creating a session here we are and we can now walk around in this session and jump and stuff so that's great now we created a session so um let's then finish up the other events that we had in here so actually set letting the person set it themselves so what we're simply going to do very simple is uh when the text changes we're simply going to change the me nextt player amount here so first we need to convert the text uh to a string and then the string will go in here now obviously you might want to check uh you might not want to do this in reality with an input box because people could also type text in there and such but for the purposes of this video that is something that would be good practice to fix on your own and to replace uh the input box to something else but we are simply using an input box to set this value and then for the lwn whether or not we want to use lwn we can simply hook that variable up here so now we can compile on Save and then if we hit play again we can create I can actually type in seven and whether or not I want to use lwn then if I create I'll actually create the session with those settings so next up is how can we actually join the session so for that we are going to go over to our main menu session folder and we're going to go into our server browser let's open that guy up and the main button here is the refresh button when we click this button we want it to load with available sessions so we're going to go down and click on the refresh event here then when we did that uh we're going to start coding it so when we refresh we want to use the find session note as we explained earlier yet again we are in the main menu so the player controller here can either be the owning player of the widget which is the player controller why is that the player controller you might ask or maybe you forgot well when we are in the main menu and when we create the widget of the main menu then we gave ourself as the owning player for this widget so since we are the owning player of the main menu we are also the owning player here but uh since this is offline in the in the main menu we can also just type cat player controller so we're going to hook this guy up this note asks for a Max result so this asks for uh how many results do we want to find well you could expose that to the player but let's set it to 50 so that we want to show 50 available sessions and it asks if we want to use lwn or not so we have not actually set up a box like that so very quickly and roughly I'm going to set up uh a little uh checkbox here and we're just going to drop it in here it's going to look uh not the nicest but it's right here and then we're going to wrap it quickly with a horizontal box and inside of the horizontal box we will put some text and we'll just make this say uh search or long question mark let's scale it down because it doesn't look nice let's put it in the middle um and then this horizontal box we're going to give it some padding to the right let's say uh 30 and maybe in between the checkbox and the text some padding to the right 15 then we're going to rename the checkbox to say uh use l on question mark underscore CB which stands for checkbox we're going to get this checkbox's event over here and that's it then we're going to promote this use Lan to a variable and call it use Lan question mark by default this may be set to uh false which is fine and then we're going to set the variable here in case that we change it so when you change it you then click refresh it updates with your correct settings let's get this Noe out of the way up to here and then we focus on this so what do we have here first of all we have a failure for when it cannot find sessions let's say your internet is down or steam is down then it would fill so we're simply going to type in print and I get a print string and say couldn't find sessions that's simply how we're going to handle the failure for now and then we got a success and a results array and the array is of the type blueprint session result structure so what is that and how can we use it well we're going to drag off of here and type in for each Loop and we are going to Loop through all of the available results that we found when we have a success for finding sessions uh and if we Hoover over these notes It also says Searchers for adverti sessions with the default online subsystem so keep in mind you cannot use this to find steam sessions but default sessions we will use steam in the near future uh but for now this is important for you to understand how everything works so what do we get out of this array here well out of this array if we Hoover over it comes a blueprint session result structure so this contains the result of the session what is the result of the session well that is the session itself so uh next up we will now need to create children and those children we made them over here so it's these and these need to be populated with these options so we need to populate them with a session name amount of players ping and the ability to join the game so the joining of the game will be coded in this Widget the server Rouser widget and here we simply going to refresh but uh like I said this is the session and what does the session have well if you type in get then we see the available options to pull from this result and the available options are get current players the max amount of players so this is how many players are in the session how many players are maximum allowed in the session that is equal to what we have set over here so that is equal to the public connection type that is the Mex and then uh and then the last one is the Ping and the server name now the name of the server is always by default going to be the name of the computer uh when you're using steam or EOS it will result in the uh host's steam or EOS name so uh but yeah so that's the data that we can get out of here but what do we want to do with the data we want to send that data to to these widgets that we want to add to this vertical box so first of all when we are refreshing the server browser we first want to clear the serf browser in case that we had previous results in here so when we click on the server list SB scroll box then we go over to the graph we see it selected here we're going to drag it in and each time that we refresh we're first going to say clear children so we want to clear the children that exist inside of this panel widget just like that there we go and then next up what we want to do is that for each result that we find so off of the loop body we want to say create widget and the widget that we wish to create is the server Rowser item now the owning player you don't have to set it but you can set it to something like the owning player of this widget so this can be the only player but like I said you don't have to do it so let's not do it and then uh we want to add this child to this server list so get the server list scroll boox and say add child and then the value here we're going to do this and we're going to put the value in here to add this child to the Ser box now if we hit compile on Save then we still see that the actual session itself we didn't do anything with that so we want to get this session into this widget and since this is of the type blueprint session result structure we're going to go over to the server browser and go over to this graph and then we're going to make a variable here which is of that same type so we're going to call this our session and if we click on the type of variable this going to be it's going to be blueprint session result here we go and then like we learned previously if we make it instance editable which is the same as clicking the I then we can expose it in such a way so if we click exposal spawn hit compile save then it will become visible here when we refresh cresh over here so now we have the option to plug the session into here so now we're going to have the server browser find sessions uh give that data of each individual session to the session items and that's it then when we complete we're going to do a print string and we're going to say refreshed and that's it hit compile and save and that's all the logic that we need for the server browser then we're going to close the server browser and go ahead and go into into the server browser item here and now we have to use that uh session blueprint session result structure to actually fill in the data over here so we're going to want to set the session name the amount of players the Ping and then the joining of it so um on event construct that's the one that we're going to need we're going to grab our session result that has been set by the server browser and we're going to drag off of it and type in break sorry that's not possible so we're we're going to drag off of it and type in get the reason that you cannot break this structure and you can break other structures is because this is a session structure belonging to the online subsystem uh installed into the engine not a self-made structure so we we cannot manipulate the structure and therefore they won't allow us to break it but what we can do is that we can drag off of the structure type in get and then get all the available data for us so what data do we want we want to get the current amount of players we want to get the x amount of players we want to get the Ping in Ms and we want to get the server name that's all that we want so uh then basically we want to change the session name text so select that select it here you can also select on the left get it and type in set text then select the set set text here and then the session name you guess it is going to be equal to this one so that's the server name let's put that on top just like that and this like this then the next text that we want to set is going to be um let's see our player type here and we wanted to display the current slash the Max and then say players behind it so first of all we're going to do a text to string so copy this one and then we're going to type in append so we're going to append the string uh and then what we want in here is the current players slash the max amount of players so let's say two out of five and then we want to say spacebar lers so uh and what what do we want to set here actually we want to set the player amount text variable so you can also simply click on the text here and then it will select the variable drag it in get it and set that and then next up is the Ping so we're going to click on the Ping we're then going to drag in the Ping get another set text note just like this and in here we are going to hook up our ping just like that okay so now that that is all set then how can we actually join it so for that we're going to click on the join button scroll all the way down un clicked get that event and on clicked we want to type in the last session function for this one which we call join session there we go now the joining of the session asks for a player controller so that one you had again is get player controller and then the search result is the blueprint session result variable so it's this one so we plug that in here and that's that now uh when creating the session off of success we set open level when joining a session you don't have to do that when you join a session you always automatically get teleported to the level that the server so the host is currently in so whether the host is has traveled uh ever since he started the session from Level A to B to C if he is in level C you will connect to level C and that is why we made the host when creating the session go from the main menu to the gameplay level we could have let the host be in the main menu and make players join the host inside of the main menu but that is not what we want to achieve here right unless you got some type of uh main menu where you want to have people connect in like server browsers and of or in like player lists and stuff but uh so it like a 2d Lobby then you can do something like that but then you would yeah basically you could do something like that if you wanted to but uh typically you would have players connect to another level like a Lobby and then from the lobby you would have the whole session travel to a gameplay level right so uh well when joining a session when you then then you're basically connecting to the session and then you are always in the map that the server is also in so you cannot have multiplayer games where the host is in this level and the other one is in this level uh you can uh you can only be in one level at the same time with the entire session so also when connected to a dedicated server a dedicated server is only one level and you will only be in that level and not in others so keep that in mind um and then yeah so we automatically join so what do we want to do here off of success well uh we don't want to do anything but what do we want to do on failure we just want to do a print string and then we want to type in uh fi to joint so that's what we want to do here now let's go ahead compile and save and that's basically all for setting up the sessions now the last and only note that we haven't used is the destroy session note but when it comes to destroying sessions um we basically need to handle errors so when when we got like uh network errors and traveling errors then we got the whole like destroying session stuff um so that is the last one that we haven't used but before we go into that I want to quickly uh explain uh I want to quickly show how how this setup works so far that we have so if we are in the main menu we're now going to have two players playing in stand alone so two offline players so this right now is just uh two types two times the same game uh running but running separately so this is an offline game this is an offline game what we're going to do is that we're going to have this right guy create a session for five players so he's now going to click on create session and he will then travel as the host into this session but now it doesn't display server cuz this is still Standalone but since he is the one that created the session he is actually in fact the server and then for the client here on the left we're going to click on find game we're then going to click on refresh we're going to wait a little bit because it's refreshing behind the scenes and there we go after a little time of waiting it said refreshed and it then displays the super long server name which overlaps the amount of players and then uh so yeah super long server name the PC name of this guy uh and then here it says the amount of players which is hard to see and then we see 12 which is the Ping and the ability to join so first of all let's quickly clean up that name cuz it's a bit messy so inside of the server item what we're going to do is that we're going to say um here we're going to say uh get length or sorry we're going to type in length and if the length is larger greater or equal then let's say 15 length then uh in that case so actually I'm going to drag off here and type in sequence so we're going to have some separate Logic for these guys and then this one we're going to drag it apart for now and set it up like this quickly so that we can code this one separately and have this one do its thing so if um let's see here so in sequence zero if this uh length of the server name is more than 15 then we want to basically chop this one so say chop uh and we want to do a left Chop well what is a left Chop returns to leftmost characters from the string chopping the given number of characters from the end so what we want to do is that we want to put 15 in here we want to have a 15 chob and then that is the text that we actually want to set here so so if it is uh longer than 15 then we're going to chop it in a case that it's not longer than 15 then we're can directly plug in the text so it looks a bit messy I'll clean this up for the for the patron project but that's basically what we want let's go ahead and click play again uh we're going to create a session let's say seven players this time create there we go and then we're going to find session refresh we have to wait for a little while and there we go so now the name is neatly chopped at 15 and then um and then we have one out of seven players 10 ping and we can then click join to test it out when we click join we see that the this guy connects to the session so we can have the bean now jumping around and there we go and then here on the right we got this guy jumping around all right guys I want to keep it at this for this video uh in the next video we are going to talk about the destroying of the sessions which is also very important uh and that will then conclude all of the session logic but since this video is already 54 minutes long um I just want to end it here because it's going to get too long when destroying sessions we're also going to be talking about handling errors so traveling errors networking errors so that's going to be all one part um so yeah I hope you guys enjoyed this video If you want to get access to the project files for this video then it's going to be available on my patreon link down below I hope you guys enjoyed this video uh I appreciate every single one of you subscribing and liking the video that helps out the channel lot and see you guys in the next one [Music] bye
Info
Channel: Kekdot
Views: 9,451
Rating: undefined out of 5
Keywords: Blueprints, Unreal Engine 5, Unreal Engine 4, Steam, Multiplayer, Game, Lobby, Game development, Unreal Engine, UE, Multiplayer game, Host game, Sessions, Advanced, Tutorial, Server browser, Online, Multiplayer Unreal, Replication, Replicated, MMO, Subsystem, Game Engine, Solution, Modular, Devlog, Listen server, Dedicated Server, GameMode, GameState, PlayerState, PlayerController, Widgets, RPC's, Player, Blueprint, Chat, Battle Royale, Shooter, Third person, First person, Loot, Spawn, Create, Find, Join, Destroy
Id: YUPZ1j_9Vzw
Channel Id: undefined
Length: 52min 26sec (3146 seconds)
Published: Fri Oct 20 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.