Unreal Engine 4 (UE4) packs a lot of features and it can be overwhelming when you are just starting out. For example, UE4 offers a nice system for saving and loading game progress, but it still can be daunting to understand and work with. My goal in this post is to show you how to get local game saves working with the system that UE4 has to offer.
Note: I am expecting that you have some familiarity working with UE4 in this post.
Creating a custom SaveGame
In order to save the progress of your game, you need to have a SaveGame class specifically defined for your project. The SaveGame object is where you can place all the information that needs saving in your project.
To create a custom SaveGame, go to the Content Browser and create a new Blueprint class. Search for “SaveGame” and select it as the Parent class. In your SaveGame class, you can add all the variables you want to keep track of. You can think of the SaveGame class as a special container object that UE4 uses to store information you want to save.
Derived SaveGame class storing the player’s scores, save name and id.
Saving
Saving your game data takes four simple steps in Blueprint. They are:
- Create a Save Game object of your SaveGame class
- Cast the return value to your SaveGame class
- Set all the variables with current values
- Save game data to slot corresponding to id and name
Here is a save game data function that keeps track of the player’s highest score and their latest score. The function returns true or false to indicate if saving was successful or not.
Note: I broke the function up into several parts, but if you combine them together, you get the full function.
Loading
Loading your game data follows a similar procedure as saving. You can load your game data in five simple steps. They are:
- Create a Save Game object of your SaveGame class
- Cast the return value to your SaveGame class
- Check if the save data exists
- If the save data exists, then load it
- Cast and extract the variables from the returned Save Game object
Here is a load game data function that checks for an existing game save. The function returns a SaveGame object if the game save exists.
Note: I broke the function up into several parts, but if you combine them together, you get the full function.
I hope you found this post helpful. If you found the post helpful, share it with others so they can benefit too.
Was there anything that I left out that you think I should include? If so, feel free to leave a comment below.
Also, to stay in touch, you can follow me on twitter.