Unreal Engine 4 - Save & Load Game EASY Tutorial

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
what is up guys today we're covering saving and loading the game so without further ado a quick thank you to my patrons for supporting me and tim my friend welcome to the team and thanks for joining okay let's jump into this so to put saving and loading the game simply it's this we have a save game slot this is basically a storage which holds onto different variables to do with our game we then have saving the game this is sending over variables to our save game slot to hold on to and we have loading the game which is quite simply restarting the level and when the level boots up again retrieving the variables stored in the save game slot to reapply to our game so let's run down an example we play a level and our character levels up we then save the game and send this level up to the save game slot as an integer then we quit and play our level again our character is now back to his starting level but we can retrieve our level stored in the save game slot and load this back onto our character therefore levelling them up again so everything resets back to normal when we play a level but we use our save game slot to load on our save stats etc so let's create a save load game so first we're going to right click new blueprint and for class type save game and bring in the save game class call this bp underscore save game so this save game is the storage i was talking about earlier where you can store variables to use for loading your game so let's jump into it and let's create a blank transform variable to store our character's location and rotation inside anything you want to save in your game you'd save in here by creating a variable and storing the value or item inside okay so we've got the storage now we need to save things into that storage and then load things from it and this can be done from a few places but i like to do it in the game mode and a game mode for those of you who don't know is basically a blueprint which keeps track of the state of your game which is always running in the background all the variables inside it reset when changing levels but as we're saving all our information in a save game that's kind of irrelevant so if you don't have a game mode right click blueprint and select game mode call this bp underscore game mode and in your world settings in the bottom right under game mode override select your game mode now double click to open it up first we need to actually create the save file so under the begin plane bring in a does save game exist node for slot name type in here what you want your save to be called i'll call mine save one bring in a branch with b and click and connect these up then off the false if a saved game doesn't exist bring in a create save game object and select your bp save game now off this bring in a save game to slot node and make sure your slot name is the same slot name you used earlier so far pretty easy right if we don't have a save game file we're going to create one and save it let's comment this create save file now let's actually save the game so right click and create a custom event called save game then bring in a load game from slot making sure you use the same slot name you've been using in the past [Music] off this we're going to cast to our bp save game and we're going to pull off this and set our transform variable we made earlier and we're going to set this value with our character's transform so bring in a get player character node then pull off this and cast to your player character whatever your character blueprint is called maybe third person maybe something else pull off this and get actor transform and plug this into our save game transform variable and finally we're going to bring in a save game to slot node again making sure we use the same slot name as we did earlier [Music] so this is everything you need to know to save the game first you get a reference to the save game we made using the load game from slot node then you do your changes to whatever variable and then you save game to slot so every time you want to save something come back to these nodes this is how you do it let's comment this save game okay so we've stored our character's location in our save game now how do we load it well we want to load our game every time we start our game right so we can go back to our begin play if there is a save game we can load our game so again we need to reference our save game so let's copy our previously made load game from slot and reference notes let's also copy our character reference nodes so this time instead of setting the save game variable we need to use it so pull off the save game and get our character transform variable let's plug in our cast 2 character [Music] and this time instead of getting the world transform we're going to set the world transform [Music] and we plug our save game variable into this transform and there we have loading the game let's comment this as load game functionality so you may be wondering how we meant to call this load game if it's part of a begin play event well as every time we begin our game our game will be loaded to our last save all we need to do is restart the level and it will load our save game so let's create another custom event called load game and simply off this we're going to bring in a execute console command and inside it we're going to type restart level which will restart the level okay now just a few more things first how do we delete a save file either for testing purposes or in-game well whenever you want to delete a save file for testing you can hop into your project folder in your file explorer hop into the saved folder and jump into the newly created save games folder here we can just manually delete the save file okay what about in-game in our game mode let's create a new custom event called restart level of this bring in a delete game in slot node making sure you use the correct slot name then let's duplicate our restart level console command and there we have it so we delete the save file and then we restart now let's hop into our character blueprint under the event begin play bring in a get player controller node pull off this and bring in a set control rotation node for the rotation pull off it and get active rotation so these nodes will just ensure our camera is always facing our character when we load back into the level okay very last thing calling the events we made in the game mode so for this i need you to either download the link in the description which contains a menu widget or i need you to create a widget with three buttons one button called restart one called save game and one called load game if you're downloading the widget once it's downloaded just copy paste the file into your content browser in your file explorer don't import it next i need you to click the link called blueprint nodes in the description when it opens just copy all the nodes and jump back into your program in the menu under blueprints hop into the level blueprint and paste all these nodes in make sure the widget being created is your menu widget that you either made or downloaded pull off this promote to variable and call it menu wb ctrl drag this variable in and connect it up to the add to viewport and remove from parent so these nodes just toggle your menu widget to open and close copy and paste it to save your time okay now jumping into our menu widget click on each of the buttons and in the details on the right scroll down until you see the events then bring in an unclicked event for each button then bring in a get game mode and cast to our bp underscore game mode from here we can call our gamemode events we made so pull off our gamemode ref and call the save game event and plug this into our save game button click now copy the game mode ref and bring in our load game event for our load game button click then copy the ref again and bring in our restart level event for our restart button click so now each button is linked to each of the events in the game mode and that my friends is how you save load and delete a save file for anyone who wants a fully integrated save and load system or for anyone who wants to speed up their learning check out my marketplace asset it's got some really awesome features and it will really help you with your unreal engine blueprinting if you're interested i'll leave a link in the description so you can check it out tomorrow we are continuing our save game journey and i'll be showing you how we can implement checkpoints and save certain parts of our level and that's it for me guys thank you so much for watching i'll see you all in the next one [Music]
Info
Channel: Beardgames
Views: 9,106
Rating: undefined out of 5
Keywords: Save Game, Load Game, Delete Game, Unreal Engine 4, Checkpoints, Game Development, Unreal Engine, Epic Games, Unreal Engine 5, Tutorial, UE5, UE4, Nanite, unreal engine, ue4, game development, Beard games, Beardgames, unreal engine 4, unreal engine 5, epic games, ue5, gamedev, unreal engine 2020, game dev, unreal engine tutorial, unreal, game developer, indie gamedev, indie game development, unreal engine 5 early access, unreal engine save game, ue4 save game, ue5 save game
Id: H2OXybjUjI0
Channel Id: undefined
Length: 9min 55sec (595 seconds)
Published: Fri Apr 16 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.