Hosting and Joining Multiplayer Games | Multiplayer Tutorial Series | Unreal Engine 5

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello guys and welcome to my tutorial about how sessions work in unreal engine so basically how you can host the game for multiplayer and how other players can then find that game that you hosted in multiplayer and join it by the way if you guys are interested in this little project it's available on our patreon you can get these project files and take a look at this yourself or use this in one of your projects so let's get to it inside of my tutorial project here i made a sessions folder and in that sessions folder i've already created some widgets which will help us understand how the sessions here work so we have a create the session widget a find session widget which is basically a server browser then we have a join session widget which is an item in the server browser so when we find sessions this is the item and eventually once we go from the main menu level into the gameplay level then at that point we can also leave the session so the first thing i want to talk about is what are sessions and how do they work well basically on our engine has what is called an online subsystem installed and the one that is standard integrated is what we call the default online subsystem so what is an online subsystem well as it says here on their own documentation page an online subsystem is an interface that provides a common way to access functionality of online services such as steam xbox live facebook and playstation and epic online services so what does that mean exactly what is that interface and what is that online functionality well look at it like this imagine that you are at home on your own local network right and that you host a session using unrare engine's default online subsystem and the nodes that our engine gives you by default so these are the nodes create session find session join and destroy so imagine that you host a session on your own local network and then that is running on your pc so your pc is then running that session then in that scenario you cannot expect that other players who are not on your own home local network can find your hosted session so what can you do well if you host a session in your own local network then your home pc one and your home pc2 could for instance find the session and join each other so if we take a look at that over here if i host a session here on the left for two players if i create that and i enter the session here then on the right here i can hit find session and then it will look for my sessions then eventually here it will find my local network hosted session and it will say one out of two players 34 ping and i can then join that game so as you see i'm now connected to my own session here hosted on my local network but let's say that i want to host a game and have other people find it well for that the online subsystem really comes into place and especially two popular ones at the moment are steam and the epic online subsystem so here we have the steam store team has an integrated back-end solution for us which allows for us to host matches on their network and then suddenly our local home network can find other matches through their system and so does epic so we have steam as an option for this and we also have the epic game store as an option for this but do keep in mind when you publish your game on steam then most likely you will use the steam online subsystem and when you publish your game on the epic store then most likely you use epics online subsystem because these subsystems do not only make sure that you can have proper matchmaking know these systems also ensure that you have for instance your friend list or that you have for instance team achievements etc etc so these subsystems do a lot more but by default unr engine has these nodes for us and what we can do by default is simply create sessions find them join them and eventually once we leave them we can destroy them and from these sessions we can get some information so let's say you find a session here you have a return of all the sessions that have been found on the subsystem that you are currently using and from that session result you can then get information and the information that is available for us by default is this information over here so we have get current players we can get the max amount of players we can get the ping of the session and we can get the session server name which in case you are hosting a session on steam is your steam username in case you're hosting a session on epic it's your epic username in case you're hosting a session on your local home network like this it's the name of your pc and we can take another look at that over here if i host the session over here and find it here on the right then we will see since i am now using the default on my subsystem that it will return my pc name which is hosting that session then let's talk about how you can get these nodes here what you're going to do is right click somewhere in your graph so typically you would do this inside of your widget graphs and you're going to type session and then if you scroll down a little bit you will get to this category called online and then you will see session and over here you see the four available session functions here and the four available peer functions where you can get information from the sessions so if you click over here on create session for instance you will get this node and then you can install it in the corresponding widget all right so now that that's clear and that we have kind of an understanding of what a subsystem is then let's look at how you can find other players on the subsystem well it's basically like this imagine that you're on your own home local network and that you are then connected to steam and your game is integrated with the steam online subsystem at that point when you host the session it will no longer be available over here but it will then be available on the steam online subsystem and as some other player that is also connected to the internet from his home and some other people in the world can find that session and that's where the online subsystems come into play now if you don't want to make use of steam or epic's online serp system then there's other solutions as well so some popular solutions for that in that case are for instance microsoft's playfab so playfob is a huge backend as a service solution and it gives us the following features so you can host your multiplayer servers there you can do content management you can have your game economy there you can also have leaderboard and statistics and things such as achievements and overall just data management so you can basically store player information and stuff like that and then you could for instance not use a steam online subsystem or apex online subsystem but in this case you could then make use of playfob's matchmaking system in order to find the matches that you expose and on playfob you could also for instance here host your dedicated servers and then these dedicated servers can be found with the matchmaking of playfob as well so that's another solution and besides playfob another popular solution is amazon's gamelift alright then as mentioned before this is the information that we can get from the sessions by default so it's not that much information you cannot for instance see the game mode that somebody's playing or the map that somebody's playing in in a session and stuff like that so to solve that the community has actually made a solution and that is what we call the advanced session plugin so this is a community plugin it's free and you can download it over here from the forum using the link in the description and this plugin for instance gives us a lot more options than what our engine gives us by default so for instance over there you can expose the game mode or the map that somebody's playing in and just show a lot more information in the server browser than what our engine here gives you alright now that we have a good understanding of what sessions are and some of the basics regarding sessions in our engine then we're going to talk about how you can actually properly integrate these nodes and how you should hook them up so to do that i'm going back to my main folder here and tell you guys about the structure that i've set up here inside of my blueprint folder i have set up a little main menu it's a simple game mode here with a player controller assigned to it and all this playercontroller does is that it starts our ui over here in the main menu this game mode is assigned in this level over here as you see then in the gameplay folder we have a gameplay game mode and a gameplay player controllers and then for that to work we have a main menu level and then we have a gameplay level so what we're going to do here is that in the main menu we're going to host the session and then once we host that session we will travel to the gameplay level in which the session will then take place and then the second player here from the main menu can use the server browser to find the session that's going on in the gameplay level from the other player and join that player alright so let's take a look at how this works first of all we're going to take a look at the create session widget here and then take a look at the graph to see how we can implement this node so basically if we take a look at the node it asks for three things a player controller public connections and use lon or not so this is a boolean which means it's just true or false whether or not we want to use lon lon means hosting it on a local network and not on the internet public connections is the amount of players that you want to allow in the session so if you set that to 8 then a maximum amount of 8 players can join in your session and your player controller is simply your player controller of your game so that's what it asks us here so the first thing you're going to do is simply promote these two variable so that we can then set these so what i have done over here and you can take a look at this simple ui structure on the left and copy it it's creating a simple editable text box here in which we can input the amount of players and then a simple checkbox here whether or not we want to use lan and eventually a button which then creates the session so we take a look at that the editable text box simply sets the amount of public connections so if our input 5 5 is set there the checkbox says whether or not we are using lon and eventually when we hit the create session button we actually create the session now first thing you need to understand is when you create the session you have to use this function over here and you get it by typing open level and once you got that you want to put the level in here which you want to travel to when you create the session so in our case we are in the main menu level and we want to travel to our gameplay level and then the second thing that you have to know is that in the options here we have to put listen and what listen means is that we create a listen server so that means that all the clients basically listen to the host and that's what is also known as the client server model and that's the multiplayer model that honor engine integrated by default so you can test that model if you click here on the top and then go to net mode and over here we see listen server which is a server client model so one player is a host and the other players are clients and join that host alright so this is the only setup you need in order to host a match so we then take a look at that if i simply type in a number like 5 over here for instance and then hit create then we travel to that gameplay level in which we can then run around and have our gameplay logic that's all for hosting a level then let's talk about how we can find sessions and then join them so if we take a look inside of the find session ui all this is is a server browser so it's basically a scroll box here and once sessions are found the scroll box will get populated with these sessions and these sessions i use this widget for it join session widget and all this really is is basically a horizontal box having a server name having an amount of players here and having ping as a text and then a join session button so to explain this joint session widget first if we look at the graph here then on event construct this widget we are going to set our server name and these are those pure functions that i've shown you guys before over here so as you see these these functions here they all ask for a result so the first thing you're going to do is right click that result and promote it to variable that's what i've done over here and then you get yourself a variable of the type blueprint session result that one we are then going to make it instance editable and expose it on spawn what that means is that inside of the server browser once we create our widgets then you see that search result here exposed which means we can then basically fill in the information in this search result variable so once that variable has been set then basically we get the server name we set it we get the max amount of players we append that to a string with a slash in here and then we set that amount of players and then we get that ping which is available for us as well and we set that being text so now basically this text this text and this text have been set we're then going to have a look at the server browser which is my find session blueprint over here so for the server browser as you see my structure is fairly simple we have a vertical box in there we have find session button we then have a little horizontal box with this checkbox in here and some text and then we have the session list scroll box which essentially just is our server list so let's look at the code here if we click the find session button then the first thing we're going to do is that that session is scroll box which i have promoted to a variable so if you click on it and promote it to variable first we're going to clear it at that point we are going to disable our find session button which will indicate to us that we are looking for a session and at that point we use the inner engine find sessions node so let's take a look at this node this node asks us for a player controller a max result and whether or not we want to use long so uselan in this case means are we searching for loan matches or are we searching for online matches so for that i used my little checkbox so this checkbox over here and that checkbox will set that variable to true or false and then the max result that it is asking for is basically how many sessions do we want to find and display to the user so you can type in 100 here which will be a very large server browser but for my example i've simply typed in 25 here now my following logic here is that if no sessions have been found which means a failure then basically i will enable that find session button again so i will set this button here back to enabled so that we can click it again to look for sessions again and on success we are simply going to have a for each loop of that result array so for example the result session array might return five sessions that we have found and for each one of these sessions we are going to create our little join session widget which is this widget which is basically a server browser item and on that widget we are then going to fill in from our array element here that search result and then we're going to add this widget to the scroll box as a child so that's only logic here and if we take a look at that then i can host a session for let's say 10 players i can click on host my session is then hosted and then if i click find session the button gets disabled and after some time you will see that my session will be found here and it will display my server name in this case the name of my local pc the amount of players 1 out of 10 currently and the ping of the session and if i hit join it will then connect to the session and i am done here okay then now that we understand the find session note let's take a look at how that join session node works so back in our witcher blueprint join session we have this event for when we click the session button and here we simply have to join session note so what does this node need well this node is only asking for a player controller so simply plug in your player controller and then the search result is asking for a blueprint session result structure so like i said before we get one by right clicking on these functions and promoting it to variable you then get yourself the variable over here we've made it instance editable and we have exposed it on spawn so that we can fill that information in and that's the session that we're plugging in here as well and then as you see on the success and on the failure i have not coded anything on the failure here most of the time she would have some feedback to the player displaying what the failure is or that you cannot join the possession and that you should try again later and on the success we don't have to code anything that is because our engine by default on the success will connect you to the map of that session so you don't have to code anything simply if you hit the join session button you will automatically connect and join that session what you could do here and what i do in the multiplayer blueprint lobby solution product for instance is that here on success i then create a loading screen and have that pop up while you're connecting all right now that we understand how we can join the session then let's look at the final thing which is how we can leave the session again so let's host one more match for that and let's join it join all right so as you see this is now the client here on the right and this is then the server the host here on the left um and now with this client decides to leave so what i've made is this little leave session button and when he clicks it he returns back to the main menu as you see and this guy here will stay in the session this guy can then also leave the session and return to the main menu so what do i do there well that's very simple if we take a look at this widget here when we click the leave session button we simply have a destroy session event and after destroying the session we are then going to open the level of the main menu here in this scenario we don't have to fill in the options string here all you have to do is fill in the level name that you want to exit to so what is the destroy session node and why do you need to use it well if you are currently in an active session or if you hosted the session yourself and you don't destroy it after leaving it then you are not able to host new sessions so you have to destroy your old session before you can host or join a new one and that is what the destroy session note is for alright guys i hope i explained it good for you guys and that you guys understand what sessions are in our engine how you can host and join sessions and i will see you guys in the next video bye bye also we have created a product on the marketplace called the multiplayer blueprint lobby solution the multiplayer blooper and lobby solution has all of these features integrated and much more such as a whole lobby system where you can ready up have character customization etc etc so in case you guys are interested in that we have that available on the marketplace view as well bye-bye [Music] you
Info
Channel: Kekdot
Views: 127,710
Rating: undefined out of 5
Keywords: Blueprints, Unreal Engine 5, Unreal Engine 4, Steam, Multiplayer, Game, Marketplace, Lobby, Game development, Unreal Engine, UE, Multiplayer game, Host game, Sessions, Advanced, Tutorial, Server browser, Sessions Steam, Ready up system, Online, Multiplayer Unreal, Replication, Replicated, MMO, Subsystem, Game Engine, Solution, Modular, Devlog, Listen server, Dedicated Server, Seamless travel, GameMode, GameState, PlayerState, PlayerController, Widgets, RPC's, Steam advanced session, Plugin, Series
Id: dQD_sPFXcBg
Channel Id: undefined
Length: 18min 58sec (1138 seconds)
Published: Fri May 13 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.