[UE4] Saving Progress in your game!

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
all right guys we're back with another tutorial we're gonna be talking about the save system inside of unreal engine how to create your own saved games and set up a single player save your progress system uh so the first thing we're gonna do well actually here i'll show you what i'm gonna do my goal for this project is this is just the um the inventory project that we made in the other videos essentially you can kind of run around here and then it adds items to your inventory which is right here so i just picked up a blue shirt whatever i want to have it save that though so i'm going to escape real quick and we're going to go down here and create a save game object so go under blueprints blueprint class and just type in save click save game select i'll type my save game for the title and then i'm going to make a savings structure and i'll show you kind of why i do that this is kind of the way that i like to do things because it keeps things clean my save structure some tutorials on youtube are probably going to have you do this a little bit of a different way everyone has their own ways of doing it i personally think that this is the best though and i'll kind of explain why as we go along this maybe you'll see why too i'm just going to save a string array which is the array of items that i have in my inventory so inventory and then to kind of go along with this i'm probably not going to add any functionality here but let's just say you want to save other things in here too like let's just say this can be the player's name or maybe we could have like a name in here and say like levels complete maybe and you can add to these as you go along and then pull them and save them and load them and whatever and i'll show you exactly how that works in just a second here the save game itself all we're going to do is have a very simple variable in here we're just going to call it's the actual save game i guess and inside here just type in what was that my save struct struct my save structure there it is so compile and you can see that this is the information that way instead of creating a bunch of variables in here you just have one structure and the reason i do that is because i'm actually going to expose this in blueprints as its own node where you can kind of make and break this structure instead of having a big stack of things on top of a node you'll see why i do that but this is kind of the best way in my opinion to do this uh the next thing and this is kind of the thing that makes my workflow a little bit unique i'll go ahead and create a blueprint function library and we'll call this my save functions and this is nice because you can just call these saves and call these loads wherever in your game so we'll just call this save game progress i guess and we'll make another one call it load game progress so now um the saving is going to be the one that's the most interesting we'll go ahead and say i think it's save game exists yeah does save game exist we'll ask and we'll kind of establish a name for this so i'll just call this my save and remember this because we're going to need to use this name several other times find out if it does exist we'll make a branch and if it does not exist we want to create it so create save game object select our class my save game which is the one that we're going to be using and once it is finished we will go ahead and actually save the stuff to it now this is actually a save game reference so we don't need to do any crazy advanced casting or anything um so we'll set uh what is it called save game it's called save game set save game to input so we actually will drag this over here so that this is now exposed so when the statement game progress is saved it will go down in here and then actually set it to the save game object and then we will actually save the slot so save game to slot the slot name is going to always be the same it's my save depends on what you want to call it but just make sure you keep it the same thing this is these slots are kind of how you would establish a slot system so for example if you want to have three or four different slots or maybe allow players to create their own slots you can name them in here like i've in the past i've done slot names like slot 1 slot 2 slot 3 slot 4 etc and it kind of makes that slot i'm only using one slot though so we're going to keep it as my safe and so if the save game does exist we're going to want to go ahead and load it so load save okay yeah load game from slot is what we want my save just copy and paste that in again and once this is finished this is just a save game object so now we can do our advanced casting cast to my saved game and then save the game to the slot now of course we haven't actually set anything up yet we need to set that save game first set save game then we can proceed and the reason we do that is the same reason we did it down here so i'll kind of read this out loud to you so it makes a little bit more sense here in just a second because you know the way this works is a little bit weird but i think it'll make a lot more sense once it's actually kind of explained in a way that is understandable so if the save game does not exist it creates a save game and then it sets that save game target and then saves the game to the slot so this actually saves the file right here if the save game does exist it has to actually establish it first we can't just pull it out of thin air so it loads and of course it returns its value so essentially this cast is just converting this to the class we created the save game class so that we can get and set this value right here and we of course set that value to what's input to the node and then once it's finished it saves a game to slot again both of these at the end are just setting the file so they save to the file otherwise it doesn't do anything this is just stored in memory so now that's probably the hardest thing is now out of the way so we'll go ahead and make our load game progress so this is going to actually output so this is i mean pretty simple we load this and we'll just get this there's going to be several different outputs just in case it doesn't actually exist if it doesn't exist here let's go ahead and actually just add that again to does the save game exist we're going to assume that it does and if it doesn't we'll just have another output node output default values so branch assuming that it's true we're going to load the game from slot and we'll just get that saved data clicking on this we're just going to go ahead and add an output i just typically remove what comes by default and then i can just drag this into the node pretty easily that's our return value i'll just name it return value and then we'll copy this and paste it down here if it doesn't exist we're just going to return the default value and if we don't want to return the default value we could return our own custom stuff too just by inputting it right here but i'm just going to recombine the struct pin and keep it the way it is compile and save so now what this is doing is when it loads the game progress it's going to load that slot the specified slot if it does exist then it's going to get the information from the save game the same way we saved it and then return it or it's if it doesn't exist it's just going to return nothing or return what we specify right here so you're pretty much done here i'll show you how to actually get this thing working essentially once you're in here you go ahead and right click and then you can type in save game and under your my save functions there will be these two functions and here they are pretty simple and you can double click them to go inside of them looks like this and they can be pretty much exposed anywhere to your blueprints you can split the struct pin you can recombine the struct pin you can make or break and pick and choose what actually gets loaded but this is essentially the way it would work you save it or you load it and then whatever you do with it from there is what you do with it the tutorial is pretty much over so thank you for watching but if you want to see me integrate it to the actual game here i'm going to do it really quick just to kind of show you an example of how it would work cool so at this point what i'm going to do is i'm just going to have a save we'll go ahead and go ahead and do save game and scroll up so i can save my game progress and really i just want to save one thing so what i would do here let's go ahead and type load game we'll load our game progress we'll drag everything into the specified place so we're just pulling we don't need to touch any of this information but we do want to change our game inventory once this is added so we'll just go ahead and save what the inventory is once it's added to the actual array and that should be pretty nice there last we actually need to load it so next what we're going to do is go into i guess when the player states actually started go ahead and do a begin play once the player's date actually is created we'll go ahead and load the game progress split struct go ahead and break this and we'll just set our inventory before anything else happens that way our inventory is the same as it was in the last instance that we played the game hide unconnected pins to keep things clean and i think that's pretty much it let's go ahead and try this out so here we are in the game i hit i don't really have anything in my inventory i'm going to go ahead and grab this blue shirt i now have a blue shirt in my inventory i'm going to close the game hit play and there's my blue shirt as it was thank you guys for watching that's how you would make your own save game system pretty simple way to do things instead of having to constantly write this code over and over again i really don't think you need to have this duplication in your blueprints so you can just have these two very simple and easy to use nodes with this little blue dot which you use as your struct if you want to add any values to this of course all you can do is just go back into your actual structure and set the items that you're actually saving right here pretty easily let me know what you guys think in the comments thanks for checking it out and i hope this helps
Info
Channel: Aaron Hunt
Views: 12,912
Rating: undefined out of 5
Keywords: game dev, music, art, film
Id: I9h2VLNk8iI
Channel Id: undefined
Length: 9min 31sec (571 seconds)
Published: Fri Dec 18 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.