UE4 Save and Load Multiplayer Part 1

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
welcome back everyone to another Unreal Engine 4 tutorial this is episode 53 and we are going to create a save and load game system that will work in our multiplayer system as well rather than just a regular single-player system which create we created in the previous video I will explain everything that needs to be done so technically you don't have to watch the previous video but it would be better if you would because that's some extra knowledge for you guys if you have been going through the whole series make sure you you stay till the end of the video because I have some important announcement to make so let's begin with the tutorial the first thing we need to create quite a few things and I will go to my third-person blueprints folder and inside of here we need to create a save file I have already created this from the previous video but if you don't know how to make this click the blueprint class type in save game and here we have this save game blueprint class I have already discreate it over here and inside of here we have all our variables that we want to save but if we want to do this in the multiplayer system we can simply delete all of these variables because they will have no use for us so now if we have our safe game we should create a blueprint structure I'm going to call this as players saves I guess seems to be a good name and in here now we need to create all of those variables so I will I will actually go to my third person character and I will look for these variables and I will recreate these in a structure so I'm gonna go and do this right now and I'll be back in a second once I'm done so now I have all of my variables set up that I want to be saved and now we have one more thing that we want to add to this save file so I will create a new variable and actually I might bring this to the top we go and I will call this player name and this is going to be the thing how we are going to detect our players by their names so I will make sure that this is a text type of a variable and I will save this now we can close this structure off and we need another structure this is going to be a super simple one so blueprints structure and I'm gonna call this as players DB and here we need two variables the first one I'm gonna call player which is gonna be an actor type and the other one is going to be the player name which is going to be a text so a simple structure now in our third person character I will create a new variable and I'm gonna call this players DB and I will use this as players DB structure and we need to make sure that this is an RI so we can fit multiple players inside of this so now we can compile and save this and let's see I guess this is all that we need as of right now for the variables the next thing what we should probably do is open up our save and we should create a new variable and I'm gonna call this saves and this needs RS s players save structure which needs to be an RI so we can store multiple saves in here so this is also set up let me see the next thing what we should probably do is create a custom controller for our character this is something that usually people have already done this far into the project but we don't have it so I will create a blueprint class of a player controller and I will call this my controller and now I want to open up my playable app let's make sure we save everything in the lobby map and now if we would click here in the world settings and here we have a player controller and we need to change this to my controller so now we can save this and go back to our Lobby map there we go so that has been set up the next thing what we should probably do is start creating the system so mmm let's begin slow the first thing what we should probably do is add the player name somehow to the player we can use a simple variable of a text type or I will do is I will do a text render component and I will call this player name render and I will make sure that this is replicated component I will move this to the top of the character so that it would be right above my character and I will horizontal alignment this to the center so now this is done and the next thing let me see what should I do probably we should create some custom events for when the player joins so I will right click custom event and I will call this player joined and I will run this on server and from here we need two inputs the first one needs to be the actor well I will call this player which should be an actor type and the other one is the player name and this needs to be a text there we go so now we can cast to third person character but not this one we need to get player character with the ID is the rope so basically we need the server character right now and from this server character we need to get players DB players DB this variable right here don't drag this in this is not gonna work I think so drag this from the third person character with the ID zero and once you have this then we need to add and we need to add to our RI so we need to split the structure pen and here we can connect the player and the player name right here so now our once the player joins our server character will get the information and add them to the player database and they will know that we have a new player in the game so now what we can do is drag from this players database and do a loop for each loop like so and now we should split this structure and now we can cast to third person character by using the player from the database and and then we need another custom event so I'm gonna create a custom event and I'm gonna call this array fresh players and this needs to be ran on server and this needs to have an input which will be the players DB with also a player's DB structure all right there we go and now we can run this event so as this third person character we need to refresh players and we need to connect the players database from the server character to this output there we go so what this basically will do is once the player joins the server server we'll add a player to its database then it's going to loop through the database and tell every single player that we need to refresh the player list this will basically set the name on the top of the head for every single player rather than just the the server player so now that this is set up we can actually comment this and this will be player play your oh my god player joint there we go and here on the Refresh player we need to set our variable like so to be this from the input so that now every single character would know what players are online but we only want to use the information that the server has given us so we are setting this for our local character from the input that we have received so I will move this up a little bit and I will do a loop now from this basically from this players database and now we need to split the pin cast to third person character so we are going to cast through every single per character that we have and we need to get the player named render which is at the very bottom usually yeah there we go so basically this component right here is this one and we need to set text on this one like so and the text comes from the loop ri element player name like this so that's all now we can refresh players and this is all set up for the replication and saving the players system so now we should probably create something that will actually allow us to type in the name so what I have already done in my UI folder I have a widget blueprint that I've called UI begin play and inside of here I have a couple of things the first one is just a simple text which says please enter name and make sure that once you have if you have this you actually don't have to have this but I have created this this one you need to scroll down till the behavior and you need to make sure that the visibility is hidden because by default it is visible so make sure that this is hidden and next we need to have a text box which is this one right here text box and the last thing we need is a button all of these needs to be variables so is variable and I have named these enter player please enter name please player name box and play button so now in the event graph let's begin by clicking on the layer name box and I will do an event on text committed and I will promote the text to a variable and I'm gonna call this layer name like so the next thing is on the play button on clicked we are going to check if this player name actually contains something I will do equals and let's see mmm this needs to have an input so I will duplicate this player name variable I will call this empty name if I compile this you can see that the name is actually empty make sure that this is empty and you can connect this right here so this basically will check if we have entered a name oops clicking in the wrong places all the time there we go so if this is true if we have not entered a player's name then we want you get this enter name please let's get this and let's set visibility on this one let's set this so this is true if this is empty and then if if this is true we want to make sure that this is set to visible so that the please enter name text would appear then I'm gonna do a delay and this delay let's say will be 5 seconds and then we wanna set the visibility back to hidden so set visibility and let's set this to hidden like so so now we have we will have a small message 5 seconds that will say please enter the name now but if this is false and we have actually typed in the player name what we need to do is cast to third person character using the get owning player pawn as a reference I guess it was the point yeah it was the pawn and now as this third person character we need to do a player joined event and this player needs to be this player right here or this reference as well fits so one of these and the player name needs to be the player name variable like so there we go and let's see the next thing what we should probably do is I guess nothing I guess everything should be fine we might have to add clear HUD event but we will see maybe we can run it without it so this is all set up I guess so we can close this now in the next thing what we should probably do is now launch this but to launch this in the previous tutorials I have created a lot of functions or create inventory create build menu create hard UI chests and all the other good stuff and now I've also created a new function which is called create widget which is basically the same function or let me recreate this what I've done is selected my inventory UI event I have duplicated it by pressing ctrl W and I called it create widget and what we can do over here is the lead this is inventory open like so and just simply drag the class in here which one it will say add pin to node and this will add an input of a user widget like so and this is basically all that we need to do I suggest that if you have all of these functions just like me the build menu inventory and I guess the character UI as well yes and maybe even the loading well loading one now loading is a different one but the character inventory and the build menu can definitely go through this one because we don't need that much that many events I will not change this in the whole project but I suggest that you do that and you change if you have running if you are running this one run rather better this one that will be way better I think so I'm rambling a lot today I guess the next thing we can so this is all setup we can go to our controller so let me find my controller so here is my controller and now in our controller on begin play we need to cast to third person character and we need to let me see what was it called get some kind of pawn was get controlled pawn yeah here is the node we need get controlled pawn and as this third person character we need to create a widget and this widget now we can select are you I begin play as simple as that so this is setup and if I'm not mistaken I guess this should technically work already so let's test this out let's press play let's host a new game and this does not work of course I know why because in our third person character in the event graph if you have followed my series on the begin play event you can see that here we have this clear HUD so basically we are destroying the begin play widget so let's delete this node we no longer need this so let's save this and let's press play again host the game and here we have a player name so I will simply press play and you see it says please enter name so I will type website QQQ first play and happens I guess that is because we do not really clear the HUD so let's see so we should go back to our UI begin play and I was thinking already that we should probably create this here but somehow I thought we don't but we do so here once we have successfully joined the game as this third person character we need to do our clear HUD event like so so basically we need to move this from the begin play to over here so now everything should work just fine let's close the game look you press play and you can see well it's mirrored but it does say what it needs to say so let's join a game let's slap in www the player doesn't know the name so I've made a small mistake which is super easy to fix go to your third person character and here we have our joint player joint this needs to be run on server and this refresh players needs to be a multi casted event so this is the mistake I made so that's why the names didn't show up now if you go to the gay and this is an e EE and this is a www character so they know each other and the names are visible on the top of their heads so now we have identified our players and this works perfectly now let's start actually saving stuff so for this what I will do is create events so let's see now we have these on the buttons and they are right here in the event graph but what I will do is create a new function and I will call this save game and in this save game we are going to create a save game object and we need to select my save game object and we need to get saves so we have our saves and also we need to drag in our players database like so so now we can loop through our players database to see what players we have online and once we have looped through our players now we need to loop through our saves like so and actually this needs to be with a break so let's do a loop with break like so that will be more convenient we don't have to loop through unnecessary stuff and the next thing what we need to do is we need to drag from our array element we need to break the result we could split the pin but if we split the pin we have way too many results and we don't need that many results all we need is the player name but we do need to split the the loop for our players database like so and what we can do now is check if this player name is equal to a player in our database like so and then we do a if branch check so this basically checks if we already have a record about this player in our save game file and if we do then we are going to overwrite it if we don't have it then of course we are going to create a new one so the next thing what we should probably do is create a local variable which I'm gonna call a local player found which needs to be a boolean single variable and now we can set this if this is true then we are setting this to true because we have found a player and it does exist in our system and then we can simply just break the loop like so I will reroute this a little bit to make it more appealing to the eye there we go so this is setup now the next thing what we should do is in this completed once we have completed the loop the second one then we need to gas to third person character using the object of a reference from our first loop like so this is getting a little complicated so keep an eye out the next thing what we need to do is do another if branch check to see if we have found somebody so let's do this so now if we have found somebody then we need to set our eye element like so and the our eye element needs to be this save so I will again drag from this save game object and I will get saves and I will move this way back here or let me see we should probably reroute this nicely so that it's not a big mess there we go and now we can I will do another video actually and now we can connect this saves to this alright setting our element because we need to set an element inside of our saves and the index needs to be an index from our second loop right here and this is if we have found a player then we are setting this up so now from the item we need to make this structure like so and I might actually move this even more back like so and now we need to get all the variables from our player and we need to set this in the only thing that we can get is this player name can go directly in here and everything else needs to come from this third person character so let's do the get health I will do a rewrite over here and I will get all the other variables as well so now I have set up all the variables right here all of them and now let's see now we should probably work on the false if we have not found a player so what we need to do then is again we need to get our save so I will get saves or let me see it's too far away so yeah I will get saves I will do a very proud somewhere around here I guess should be good another reroute somewhere over here should be good and I guess I need to move this back because it's too close and from the false we need to do a add to this awry so let's add I will split the pin and connect this to the false I will do a reroute for the name to get the name same the same name as for this one and so basically we haven't found a player so we need to add the variables so again we need to get all of these variables variable but I will do just simply is copy all of these move them over here and connect this to the third person character and reconnect all of these pins so there we go this is also setup and the last thing that we need to do is go to the first loop and once this loop is completed we need to save game save game game to slot there we go and the save game object is this one the one we have here and the slot name what was the slot name again game slot one I guess make sure you remember this we will need this in the load so I will actually do a reboot over here and we connect this like so so this is all set up for the save a little bit messy but well it is what it is and yeah I guess this is all set up nicely now we can go to our event graph and here we have our save and I will delete my single-player system I no longer need this and also on keyboard one pressed if this has authority then we are going to save the game like so so this works perfectly and now we need another event for our loading so let's create a new function which I'm going to call of course load game and this is going to be a lot more simpler what we need to do is load game from slot and the slot name was game slot 1 then we need to cast to save the game like so and now we should probably add a input to the load game because we need a our player name so we can find it so that we don't have to load the game every single time so the server character wouldn't have to load the game every single time a player has joined so we have this set up and the next thing what we should probably do is get our saves we should loop through the saves with a break I guess or let me see yeah let's do this with a break and we can split the pin oh no no no no no no recombine let's break the structure and this will be a lot nicer note and we need to check if the player name is equal to the inputs given name like so so now let's do a if branch check see if we have found a player and then again another local variable which is gonna have the same name local player found and if we have found it then of course we are setting this to true and we are running the execution back to the break to stop the loop from unnecessary looping I guess so this is all setup move this up a notch there we go now that this is all set up what we can do is check to see if the player has been found now we need to get our players database and we need to do another loop with a break there we go so true and we can split this pin and we need to find a player with an equal name to the player that has been found so we can simply connect this up here or yeah we need to connect this up here like so and let's do a if branch check to see if we have found it once more just to make sure that this actually does work like it is supposed to and we wouldn't run into any unnecessary issues and once this is done we can cast to third person character like so so now this is actually all set up and what we need to do is get all of our variables well we need to set our variables so set health and for now I will do a set max health as well what we need to do all of them so we have gotten the variables and now we need to go back to the saves loop and we need to get this all right element whoops we need to break this over here I think so let me reroute things a bit there we go now we can open this up and simply connect the health to health and max health to max health like so and now let's get all the other variables that we need to set up so I've gotten this far and now we need to connect theater person character over here and just run this all in a line just like we did in the previous video so this is all set up now we can go to our event graph and we can disconnect this keyboard to key we no longer need this but we want to be able to load the game on player join so let's find our events for the player join and refresh and let's see now that once the player has joined we can also from the third person character we can drag and do load game like so and connect the player name to let's see the player from over here this one right here so player name there we go so now we compile and save this let's press play cause the game QQQ one to 700 won join the game www let's pick up some items so we have picked up quite a few items this is our inventory the server character presses the key - we leave the game let's play again how's the game QQQ this one joins www and boom our inventory is not maybe it just required some pin reconnections to be working or maybe I didn't compile this successfully but now if we would host a new game and I will call this YouTube the player is gonna be YouTube and the joining player is gonna be is awesome because YouTube is really awesome it has so many great tutorials videos and information that we can learn from so I will pick up some items on this character and I will go and pick up some other items on this character now as the server I will press keyboard key one to save the whole thing I will leave the game and now if we join the game again and this time is awesome is gonna be our server character and the client character is going to be YouTube so basically they are switched places so you can see that the this character has his items and this character also has his items so everything is working right the multiplayer saving system is working as of right now it does not save the equipped items fully it kinda does it kinda doesn't because if you are following my series only to create this project the equipment is not being set up on the server side it is only being set up on the client side the only thing that is set up on server side is the visual side of the skeletal mesh that you can see on my head in this case the Hat which follows our character but we are going to work on this in the following videos and now I have a really quick announcement to make for the players players for the viewers that are following the whole series unfortunately I'm not going to be able to continue these series for much longer because I have a lot of things in my life going on right now I'm about to move and I will no longer be able to use this PC that I'm using right now and I don't think that my laptop is going to be able to handle this project because my laptop is not that great but the good news is a lot of people have enjoyed my build mode series which i think is really great but there are a lot of improvements that we can make on this so somewhere around Christmas New Year ish somewhere there I will create a tutorial series for the build system which is going to be way more better than this one with a lot more capabilities of building creative stuff and also I will be posting some tutorials tutorials on blender how to create your own models your own items to add to your game and also I will be sharing a lot of free assets as well like like I did in the in the previous videos so thank you guys for saying thank you guys for watching thank you guys for subscribing and share this with your friends develop awesome games and I see you guys in the next video bye
Info
Channel: It's Me Bro
Views: 12,039
Rating: undefined out of 5
Keywords: ue4, save, load, system, tutorial, game, survival, series, multiplayer, replicated
Id: gry8N6zRk2E
Channel Id: undefined
Length: 37min 1sec (2221 seconds)
Published: Fri Oct 25 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.