Saving and Loading Your Game

Overview of how to save and load your game

Choose your implementation method:

Blueprints

C++

The meaning of "saving the game" can vary considerably from one game to the next, but the general idea of enabling players to quit the game and then resume where they left off at a later time is a part of most modern games. Depending on what type of game you're making, you may only need a few basic pieces of information, such as the last checkpoint the player reached and maybe which items the player has found. Or you may need much more detailed information, possibly involving things like a long list of the player's social interactions with other in-game characters, or the current status of a variety of quests, mission objectives, or subplots. Unreal Engine 4 (UE4) features a saving and loading system that revolves around one or more custom SaveGame classes that you create to meet your game's specific needs, including all of the information that you need to preserve across multiple play sessions. The system supports the ability to have multiple saved game files, and to save different SaveGame classes to those files. This is useful for separating globally-unlocked features from playthrough-specific game data.

[INCLUDE:making-interactive-experiences/Tutorials\saving-and-loading-a-game/Blueprints/#CreatingSaveGame]
[INCLUDE:making-interactive-experiences/Tutorials/saving-and-loading-a-game/CPP/#CreatingSaveGame]

Saving A Game

Once you have created a SaveGame class, you can populate it with variables to store your game's data. For example, you might create an integer variable to store the player's score, or a string variable for the player's name. When you save the game, you will transfer that information from the current game world into a SaveGame object, and when loading a game, you will copy it from the SaveGame object to game object like Characters, the Player Controller, or the Game Mode.

[INCLUDE:making-interactive-experiences/Tutorials/saving-and-loading-a-game/Blueprints/#SavingGameInner]
[INCLUDE:making-interactive-experiences/Tutorials/saving-and-loading-a-game/CPP/#SavingGameInner]

On development platforms, saved game files use the .sav extension and appear in the project's Saved\SaveGames folder. On other platforms, particularly consoles, this varies to accommodate the specific file system.

Loading A Game

To load a saved game, you must provide the save slot name and user ID that you used when you saved it. If the SaveGame you specified exists, the Engine will populate your SaveGame object with the data it contains and return it as a base SaveGame (class USaveGame) object. You can then cast that object back to your custom SaveGame class and access the data. Depending on what kind of data your SaveGame type contains, you may want to keep a copy of it, or simply use the data and discard the object.

As with saving, you can load synchronously or asynchronously. If you have a large amount of data, or wish to use a loading screen or animation during load time, we recommend the asychronous method. For small amounts of data that load quickly, a synchronous method exists.

[INCLUDE:making-interactive-experiences/Tutorials/saving-and-loading-a-game/Blueprints/#LoadingGameInner]
[INCLUDE:making-interactive-experiences/Tutorials/saving-and-loading-a-game/CPP/#LoadingGameInner]
This page was written for a previous version of Unreal Engine and has not been updated for the current Unreal Engine 5.2 release.
Help shape the future of Unreal Engine documentation! Tell us how we're doing so we can serve you better.
Take our survey
Cancel