Unreal Engine·Blueprint

How to Build a Save System in Unreal Engine 5 (Blueprint Only, 10-Minute Setup)

How to create a simple Unreal Engine Save System using Blueprint in 10 minutes. You will learn that it's quite simple to create a Save Object in Unreal Engine and how to set its values and finally save it to disk.

Introduction

For my small horror game I needed to save some data for the secrets in the game to work properly. I like to manage save data the same way that some old games do, as I find it’s an incredibly simple but effective way to do it.

So for Escape Floor Zero I created a SaveGame object in Unreal and there I created a single variable: A Map of Names to Integers.

In this article you will learn how to build a super simple Save System in Blueprint like this to be able to save your game progress.

Creating a SaveGame Object in Unreal Engine

To create a Save Game Object in Unreal, right click on the content browser and then choose the Blueprint category. Once there, search for SaveGame and click it.

This will create a new SaveGame object in your content browser, you can name it whatever you like. All your game save data will live here.

What we will do now, is create a new variable, you can do that by pressing the ”+” button on the right of the Variables section.

You can call this variable what you want, but as we want to store everything in here, we will call it SaveData. This variable will be a Map of Names to Integers.

And with this our Save Object is ready on the data part.

Creating the simple Save System using the Unreal SaveGame Object

Our SaveGame class is ready, now we need to use it.

The first thing we need to do is to create it or load it once the game starts. This can be done in many places ( Game Instance, Game Mode, Custom Logic… ). In this case we will do it in the Begin Play function of our Game Mode.

Let’s break a little bit down what we are doing here:

  1. First we are trying to load a SaveGame file called “SaveData” ( this has nothing to do with the variable of the same name, this is the name of the actual file that will exist in the disk )
  2. If the file is found, the SaveGame is loaded, so we Cast it to our SaveGame type that we created and assign it to a variable, to be used later
  3. If the file is not found, this means that no SaveData exist, in this case we create a SaveGame of the type we want, store it in a variable, and write it back into disk

With these simple steps we have our save system already working, that will create a new save if no data is found or will load the data into memory if we found it in disk.

How to Read and Write data to the Save Game Object

Now that the system is ready, let’s see how we can read and write data to it.

The way that we have setup things, we have a SaveGame Object that has a single variable called “SaveData” in which we will store everything, so the way this will work is the following.

If we want to store anything we will assign a “Name” to the thing we want to store and then hold its value, let’s see some examples:

  • Player.NumDeaths -> 3: This will store that the player has died 3 times
  • VisitedLocations.SuperCoolCity -> 1: This will store that the location “SuperCoolCity” has been visited
  • NPC.TownVendor.ShopLevel -> 5: The shop level for the town shop npc is at level 5
  • World.DefeatedEnemies.Dungeon07.DragonMonster07 -> 1: A specific monster at a specific location is dead

We could go on, but as you can see a simple system like that is incredibly versatile in all the information it can hold.

Let’s see now how to write data into the savegame.

You remember that we stored a variable to the SaveGame object in the Game Mode, now it’s time to use it, to make things easier we can create some functions in the SaveGame object, it’s a Blueprint Object after all.

In the end, internally we are doing this:

We are inserting the value in the map and then we are writing the file to disk.

You will notice that in the function I created, I added a “PerformSave?” input. This is because writing a file to disk can be expensive, so instead of always writing to disk, we can keep those changes in memory, and only write to disk in certain cases, like after some time, or if you defeat a boss, or other important events.

Reading SaveGame data is even easier, as it’s simply finding it in the map.

The boolean output will tell us if the value even exists and the integer output will be the value itself.

As you can see it’s incredibly easy to use and at this point the Save System is complete.

Lots of games use a system like this. If you know Pokemon or RPG Maker, you’ll recognize it, it’s close to how they track state. Bigger games do the same thing at a larger scale: that’s roughly how Zelda: Breath of the Wild stores the enemies you’ve defeated, the locations you’ve visited, and its quest and world state.

Recap

  • The whole system is one SaveGame object holding a single variable: a Map of Name to Integer. You namespace the keys yourself ( “Player.NumDeaths”, “World.DefeatedEnemies.Dungeon07” ) so one map holds everything.
  • On Begin Play you load the named save file; if it isn’t found you create a fresh SaveGame and write it. That create-or-load step is what the rest depends on.
  • Writing to disk is expensive, so keep changes in memory and only flush on meaningful events. That’s what the “PerformSave?” input on the setter is for.

What this doesn’t cover

The map stores names to integers, so it holds flags and counters, not structs, transforms or floats without extra work. It also has no save-format versioning: rename a key or change what it means and old save files won’t migrate on their own, you handle that yourself. I didn’t get into async saving or multiple save slots either. For a small game none of that matters much; for a bigger one you’ll want a plan for it.

Keep reading

How to Create Procedural Levels with Level Instances in UE5

How to Create Procedural Levels with Level Instances in UE5

Create the Procedural World of your Dreams
Best Udemy Unreal Engine Courses: Blueprint, C++ and Gameplay Abilities

Best Udemy Unreal Engine Courses: Blueprint, C++ and Gameplay Abilities

Learn Unreal Engine fast!
GiveAbilityAndActivateOnce: One-Shot Abilities Without the Cleanup

GiveAbilityAndActivateOnce: One-Shot Abilities Without the Cleanup

Grant an ability, activate it once, and let GAS remove the spec by itself.