Unreal Engine 4 - Save Your Level & Checkpoints

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] what is up guys today i'm going to be showing you how you can save your level and what i mean by save your level is that if you open a door and restart the door is still open if you loot the chest and restart the chest is already looted that kind of thing and i'm going to be teaching you this skill by creating checkpoints before you watch any more this video is a continuation from my previous save tutorial so make sure you've watched that one before doing this one i'll leave a link in the description last thing before we start a huge thank you to my patreons for continuing to support me and zayn thanks for joining the team you guys all been great so thank you for that okay let's get into this so the first thing we need to do is fix a problem with our save game and changing levels so let's jump into our save game and create a new bull variable and we're going to call this use saved location now let's hop into our game mode so at the moment we're saving a location and then we're sending our character to that location when restarting and loading the game the problem with this is that the saved location will apply to all our maps and levels so we need to tell the program not to send us to the saved location when we're changing levels so let's move our load game functionality to the right but let's keep the reference to the save separate now let's pull off our save game and bring in our use saved location variable we just made [Music] then connect this up to a branch with b and click and coming off the true plug in our load game functionality so now by changing our you save location to true we will spawn at the saved location if it's false we will spawn at the player's start so let's create a custom event called change levels then let's duplicate our save game reference pull off the save game and set the use save location to false then let's save game to slot with the same slot name we had earlier and plug the save game reference into the save game object now let's move down to the save game and let's move our save game to slot over to the right let's pull off our save game and set our you save location to true and connect these up so when we save our game we load in with our saved location when we call the change level event we load in at the player start now whenever you're changing levels all you need to do is call your save game and change level events before changing levels this will save our game progress and then set it so we spawn at the players star in our new level cool now the checkpoints and saving the level so let's jump back into our bp save game add a new variable and call it checkpoint used as type actor and then convert it to an array remember anything you want to save must be stored inside this blueprint as a variable now back into the content browser let's right-click blueprint actor and call this checkpoint double click to open it up and let's add a box collision in the details let's turn off hidden in game so we can see it and then let's jump into the event graph so we want the checkpoint to be destroyed if it's already been taken so off the begin play let's bring in a load game from slot node with the slot name being the same one as we used earlier off this we're going to cast to our bp save game and then we're going to pull off the save game ref and bring in our checkpoint used variable we made earlier then pull off this and bring in a contains item node pull off the other input and bring in a reference to self then bring in a branch with b in click and connect all these up together and if the branch is true we're going to bring in a destroy actor node so when we play if our checkpoint actor is inside the checkpoint used variable in our save game we're simply going to destroy the actor now click on our box collision and bring in a event begin overlap node then let's duplicate the line of nodes we made a second ago by selecting them and pressing ctrl w to duplicate them connect these in coming off the component overlap so we can disconnect our destroy actor and move it to the side for now now off our bp save reference let's get another reference to our checkpoint used variable then pull off it and bring in a add node then off the add input let's get a reference to self let's bring in a save game to slot node with the correct slot name and plug our reference into this and connect everything up and finally let's bring in a get gamemode mode cast to our bp game mode then off our reference call the save game event and drop our destroy actor on the end of this so what are all these nodes doing well first we're checking if the checkpoint has already been taken and if it has we're doing nothing sometimes the begin play destroy actor will trigger after we've overlapped the box so we need this just to make sure we don't get the checkpoint again then we're adding this specific checkpoint actor to the checkpoint used variable and we're saving the game in the game mode which saves our location so now we've added our checkpoint into the checkpoint used variable our contains bool will trigger true so let's drag some of these checkpoints into our level and test it out and as you can see it's all working correctly so you may be thinking hey john you've showed us how to make checkpoints but you haven't showed us how to save things in our level at all and that my friend is where you're wrong let me break down the steps to save things in your level so first you add a variable in this bp save game with whatever you want to save in the level we created a checkpoint use variable for our checkpoint saving then in the actor you're saving you send over the information you want to save to the save game we did this in our checkpoint by adding our checkpoint to our use checkpoint variable and the last step is on the begin play to retrieve that save game information and use it to load your actor so here in the checkpoint we retrieved the save game information and we used it to destroy the checkpoint if it was already taken okay let me give you some more examples let's say you want a door to remain open after opening it well you can do the exact same thing we did for the checkpoint but if the door is inside the door used variable we send the door to its open location instead of destroying it so you can just call your open door event if you've got one or you can just set the world location to where the door would be if it's open let's say you want to pick up a sword and drop it and this new dropped location is saved for next time you play well for this example you'll need to store two variables inside the save game the actor reference and the swords transform meaning location rotation and scale so what you can do is make a struct containing all the variable information you want to use then you can add the structs to the bp save game as a variable just create a new variable and type out in the variable type field the name of your struct make sure this is an array if you want to do this for multiple actors and then back on the actor after sending over the information to the save game on the begin play you can use a setup similar to this you can retrieve the struct variable from your save game reference throw it in a for loop break the variable up and filter it using a branch and an equals node from there if the actor is saved inside the save game you can use whatever information you sent to it so in this case we can use the transform to send the sword back to its original position by using these examples you can create all types of different saves for your games and that is it for me guys if this video helped you it would be super awesome if you could like comment subscribe or check out my marketplace asset that would be so epic thank you guys so much for watching as always and i'll see you in the next one [Music] you
Info
Channel: Beardgames
Views: 14,471
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: _iJrdVuS5xE
Channel Id: undefined
Length: 8min 49sec (529 seconds)
Published: Wed Apr 21 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.