Save & Load Game (Statistics, Location & More) - Unreal Engine 4 Tutorial

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] hey guys welcome back to another unreal engine 4 tutorial and today i'm going to be showing you how to save and load a game and in this specific example statistics for example jumping as this was requested so this will be a basic general save and load game files then also we're going to have it so it saves and loads that on the jump key so when you jump it saves and adds up the jump statistic so you know how many times you have jumped and obviously you can change this so that it saves on a save button or loads on a load button whatever like that but let's get into it so to start off we're gonna have to make the save game itself so if we just right click here in the content browser go to blueprint class and then here where it says all classes open that drop down menu and then search here and just search for save game get that one select it and call it whatever you want i'm just going to call it save game like that and then open that up like so and this is basically where you store all of the variables that you want to be able to save so if you want to save the location you want to save how many times you jump do you want to save like ammo or if you making a first person shooter anything like that that's where you'd have it so like i say i'm going to be doing the amount of times the player has jumped so you just obviously make a new variable over here i'm going to call this jump count like so and because it's a numerical value i'm going to make it an integer like so then compile and this is it done for me because that's the only one i'm doing but again this is just where you store all of those variables for whatever you want to save so you can minimize that and then go to the third person character or just your character so it could be first person anything like that load it up and then obviously because i'm doing off jump i'll do it down here where the jump is so over the variables again over the left we're just going to hit a new variable and i'm going to call this saver subclass like so and then as the variable type over here it's going to search for save game now you want to make sure it's different to it's not the one that we made so actually i'm going to rename this to save game stats for statistics just so we know which ones which go back search for save game and we just want the normal save game like that and object reference now if we zoom back in down here obviously i'm taking off the jump but you can do this wherever you want so it can be off a button press or anything like that i'm just going to right click and get does game save exist like so and then this is where we're going to put in the new slot name that we want so i'm going to call it game save one and this one and you want this to be different from any other game save you have and different to the saver subclass that we made so not save game stats like so and then i want this to happen when we jump so i'll plug that into there and then off of the return value here it's red so it's a boolean so we're going to come off and get a branch as this is true or false and if it's true so save game does exist then we're going to want to load game from slot like so and we want this to be the same slot name here so i just copy and paste that into there or a helpful trick so that you know it's always going to be the same variable you don't need to check the spelling each time is if you make a new variable call it game save one or just the save of the name of your game save slot there and then under the variable type you just make it a string there you can just plug that into the slot name and there you now know it's the same spelling each time it's just a helpful tip especially if you have a lot of them and you don't want to copy and paste each time make sure you actually have written the string in this variable as well and then also if you then want to change the name you can just change it in this variable here and it will change it for all of them at the same time so under the false what we're going to want to do is if the game save doesn't exist we're going to want to create save game object like so and our return value for both of these we're just going to simply set our saver subclass that we made earlier so i'll just copy and paste that put it down here plug it in like so there we go and then off of this we're just going to simply cast to our save game we made so cast to save game stats like that and we'll do that for both of these like so and then as this this is where we're gonna add save game stats is this is where we're gonna basically get all the variables that we want to save so i could say for this example i want to do the jump count so i'll do is get jump count like so and like i said i'll do that for both of them like that and then because i'm just going to be adding one on every time i jump i can just do an increment node which is just two plus sounds like that increment integer and plug it in and what that does is basically just adds one so i'll just do that again like that and then we just want to take this back into the save game to slot like so and obviously slot name back in there again and we're gonna do this on both of them again so save game to slot like that plug that in there and then for the save game object it's gonna be our save a subclass like so so i'll plug that in and move that down there this should now be done but just to be able to do a test we're just gonna print this string from here so if i just print string like that there we go and do that on both of them for when it saves and loads then compile and this should now be the basic part done oh well this should now be done and it's just the basic part for me obviously because this is just saving and loading the jump stats but obviously you can change this for everyone so it doesn't have to be off the jump you do it off button press for save game or load game or anything like that and you can have it for different things such as the location of the player or location of different objects or the amount of health you have the amount of stamina anything like that and obviously health would be an integer or a float sorry stamina would also be a float and then location would be a vector and so on and so forth like that and if you want more examples of these in different in future tutorials uh just let me know down below and then one final thing actually as well is we need to under the create safe game objects at the start here we need to just select our save game so mine is safe game stats like so now for chester so hit compile minimize this and hit play we will see that when we have whenever we jump press space up in the top left there it goes up so i test it out before which is why i didn't start at one but it should for you so every time you jump it goes up like that and if we leave the game come back in jump again it starts off where we left off so it's at 16 now leave go back to 17 18 19 20. so you can see this is now working perfectly it's loading and saving the game and saving all the statistics that we chose again obviously you can choose this for whichever you want and do this as many times as you like and however you like but this is the basic one that i'll be going through in this video so i think that'll be it for this video i hope you found it helpful i hope you enjoyed and if you did make sure to like and subscribe down below so thank you for watching and i'll see in the next one [Music]
Info
Channel: Matt Aspland
Views: 24,345
Rating: undefined out of 5
Keywords: ue4, unreal engine 4, unreal engine, tutorial, ue4 tutorial, unreal engine 4 tutorial, how to make a game, how to, 3d modelling, blender, unity, games design, graphic designer, save, load, and, system, quick, easy, quickly, save game, game, button, on, press, sub, class, sub-class, subclass, saver, vector, location, stats, statistics, ammo, health, stamina, jumps, deaths, jump, slot, from, game save, bp, blueprint, blueprints, variable, variables, floppy disk, how to save, simple, custom, customisable, add, to, increment
Id: coPqS4eTphM
Channel Id: undefined
Length: 8min 18sec (498 seconds)
Published: Tue Jun 23 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.