How to save and load game saves in Unreal Engine 4


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:

  1. Create a Save Game object of your SaveGame class
  2. Cast the return value to your SaveGame class
  3. Set all the variables with current values
  4. 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.

Saving in blueprint step 1 and 2

Saving in blueprint step 3

Saving in blueprint step 4

Loading

Loading your game data follows a similar procedure as saving. You can load your game data in five simple steps. They are:

  1. Create a Save Game object of your SaveGame class
  2. Cast the return value to your SaveGame class
  3. Check if the save data exists
  4. If the save data exists, then load it
  5. 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.

Loading game save step 1 and 2

Loading game save steps 3 and 4

Loading game save step 5


 

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.

 


About Steven To

Steven To is a software developer that specializes in mobile development with a background in computer engineering. Beyond his passion for software development, he also has an interest in Virtual Reality, Augmented Reality, Artificial Intelligence, Personal Development, and Personal Finance. If he is not writing software, then he is out learning something new.