UE4 - Tutorial - Save and Load

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello guys and gals welcome to a new tutorial in today's video we are going to be covering how you can save and load game data using Unreal Engine 4 now obviously this isn't just going to be like you can go to file and press save this is gonna be how you can save actual game data once the game is running it's not too complicated but if you don't know how to do this hello misdemeanor if you don't know how to do this then it's the static can seem to be a little bit overwhelming but I'm gonna help you guys understand it a little bit better and hopefully at the end of this video you'll be able to set up some more complicated safe game systems so I'm just doing the third-person example map you know my number one go-to for stuff I've created myself a little folder here which is just safe saving tutorial now you can place these wherever you want it's suggested that you keep all of your files saved in specific locations you know having to have a hierarchy for things so that you can find things easier and so that if there's more than one person working on a project if they you know you can all find this stuff that you need to so the first thing we're going to do is we're just going to right click head to blueprint class and then rather than using anything on the list we're going to head to all classes which for you will be collapsed click all classes under search search for the safe game and you can see here we've got object and then we have sick in so that safe game select and then we're going to call this test underscore save now this guy is just a an empty blueprint which will allow us to store variables and call it whenever we need to so I'm gonna create a new variable I'm gonna change this from a bool to a vector and there is not going to do this as one of the things I want to save is the player location I'm gonna call this player in fact location safe so I'm gonna call this location safe I'm gonna press compile I'm going to make this public so that I can get it whenever I need to and the default I'm just gonna leave the default as sir sir-sir now I'm gonna select a third person character this is where I'm gonna store most I'll fee save data and I'm gonna press edit over in the world outliner now that he's open what I can do is I can create a new variable and this robo is going to be player lock we're gonna change this to a vector and now what we're gonna do is I'm gonna sign a couple of keys for saving so I'm gonna say keyboard one so keyboard 1 is how I'm gonna save now you can use you can do this however you want if you wanted it to be on overlapping a specific trigger box you could do that if you wanted it so that they have to be standing somewhere in to press a button and you can do that you can do it through menus it's going to be the same sort of deal after this point however you decide to input it it's up to you but after this the logic is going to follow through that it's the same way I'm going to do is we're going to create a save game object the class is going to be our save game blueprint so I'm called my intested the return value we're going to promote to a variable and we're going to call this safer then we are going to we need to get our player location so first thing we'll do is we'll see from the player location we will set this we will get actual location like so plug that into here then from our safe reference we will set it was our location safe set location save like so we'll set the location safe to our neighbor location is now we could just bypass that but certain things we are going to need to set a variable so I'm doing this here just to show you the workflow I'll set up another example afterwards but you'll see why we need to to pull from specific variables at the same time shortly next thing we will do is we will save a game just slopped I'm going to call this test the safe game object is going to be dragged from a create safe game object like so and then what we will do is we will just print a string which will say game saved I will compile this closest down press play and if I press 1 on the keyboard you can see in the corner is saying game saved which is all well and good but for now we can't actually do anything with that so we're going to reopen the third person blueprint we are going to find it keyboard you guessed it keyboard - now here what we're gonna do is say does safe game exist slot name test so reason we're gonna do this is so that we can't just load no data at all or branch this return value if false we're not gonna do anything at what we false we'll print a string pristine what is that I don't wanna print sting pretty string no data exists no shouldn't get that happen but I'm doing it just in case so if we don't ever have a safe game in that slot then it's gonna load our defaults which in this case we'll move a player to zero zero zero which we don't really want what we will do now is if true we will load a game from slot slot name is test the return value we will cast it just to our save game blueprint we're casting to a test save now we need to set a local player location so the one inside the said person character as test save we will get location save and plug this in like so and then what we will do is we will set after location because obviously we need to tell the player character itself that it's got a new location to head to like so now if we push play and I press one we'll get two game saves I'm gonna run to the top of stairs I will save the game run down a foot press two we move back to the stairs okay now this should persist across across gameplay so if I'm here now and I press two you see it's remembered the game saved from before and that's exactly what we wanted it to do so can we use this slightly differently yes and this is going to be that this other little thing that I briefly mentioned so let's move this down a little bit we're gonna need a bit more space what I'm gonna do is I'm gonna set up another key for adding some points so what a variable we're going to change this to an integer and I'm gonna call this school compile that very quickly and then I will say keyboard three in fact we'll do a mess left so nice left button we will set our score to score that's ten and what we will do is we will print string and plug a score variable in true create a converter from integer to string and that will now print a score for us so if I compile this and I head into the game if I left click you see now it's printing a score incrementing by ten every time I click great really easy game clicking gets cool not cookie quick oh yeah no hey those games so lame you were making so much money because they've made a game that automatically increases an integer great good job all right that was very cynical wasn't her old meow next thing we're going to do is we're just going to update the actual safe function itself so what we'll do here is we will drag from oh no we won't we have to open test save give this a new variable integer school save compile this leave it as default of 0 and then from our safe game object in the third person character which is on a initial press of 1 we will set score save we are setting a score save to our score so just drag on focus Corinne update these pins I guess so no and then unloading we need to do the same sort of thing we need to get score save and set score locally to what score save is and then what we will do is we will just quickly print a string for score to show whether or not it's actually brought over the correct and value so we'll compile that well press play I'm gonna left click 30 40 50 60 70 80 I'm gonna press one to save I'm gonna move away just to make sure it works opera stew and you can see now I've still got 80 points and it's placed me back red should be one to save to and you can see there got it all working lovely jubbly yeah you can go a little bit further with the player location if you needed to save the play location you can actually save the angle that the camera is currently at by rather than saving the location you can save transform and then you can get the transform of the camera itself but then you also need to plug in this scale of the character now the scales probably always just gonna be a default of 1 1 1 but in case you've changed your character scale for whatever reason you can save that as well hopefully some of you guys found that useful and you'll be able to create some pretty the safe functions of your own hopefully that explains the system - II okay so thanks for watching and see you next time
Info
Channel: Dean Ashford
Views: 55,075
Rating: undefined out of 5
Keywords: UE4, Tutorial, Unreal Engine, Save, Load, Saving, Loading, Game, Data, Indie, Dev, Student
Id: VqdjnLxCkyk
Channel Id: undefined
Length: 11min 23sec (683 seconds)
Published: Mon Dec 18 2017
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.