Saving Your Game with Blueprints

Create a SaveGame Object

To create a new SaveGame object, create a new Blueprint Class . When the Pick Parent Class dialog pops up, expand the Custom Classes dropdown, then select SaveGame. You can use the search box to jump directly to SaveGame. Name your new blueprint MySaveGame.

savegame.png

In your new SaveGame object Blueprint, create variables for any information you would like to save.

In this example, there are also variables declared that will be used to store default values for the SaveSlotName and the UserIndex, so that each class that saves to this SaveGame object will not have to independently set those variables. This step is optional, and will cause there to be one save slot that gets overwritten if the default values are not changed.

SaveGameVariables.png

You can set default values for the variables after the Blueprint is compiled.

Saving a Variable

This is a snapshot of the entire saving setup. You can click the image to enlarge it.

First, create an instance, or copy, of your SaveGame object, using the Create Save Game Object node. Make sure you set the Save Game Class dropdown to the name of your new SaveGame object Blueprint, in this case, MySaveGame. Because the Create Save Game Object node creates a generic SaveGame object copy, you have to drag off of the Return Value pin and Cast to MySaveGame. Save the result of the casting to a variable by using Promote to Variable so that you can reuse the SaveGame object easily later on.

SaveGameBP_1.png

Now that you have a copy of your custom SaveGame object, MySaveGame, saved to the Save Game Instance variable, you can send information to it. Here, the Player Name is being set to "PlayerOne". You would repeat this step for any other variables you wanted to store information in.

SaveGameBP_2.png

Now, you can use the Save Game To Slot node to save the SaveGame object's information to the hard drive. The Save Game To Slot node takes in a file name and a user ID, which in this case, are the default values created earlier.

SaveGameBP_3.png

Loading a Variable

This is a snapshot of the entire saving setup. You can click the image to enlarge it.

This first step is optional, and is based on saving a default save slot and user ID within the SaveGame object. Here, an empty SaveGame object is first created, so the default SaveSlotName and UserIndex can be read from it. Again, this may not apply in all game implementations.

LoadGameBP_1.png

You can use the Load Game From Slot node to create an instance of your SaveGame object Blueprint. Just like when you created a SaveGame object for saving information, you need to cast to your specific SaveGame object Blueprint so that you can save the result to a variable for easy access later.

LoadGameBP_2.png

Once the new SaveGame object has been loaded from the hard drive, the variable values can be read from it and assigned to the necessary Actors or classes, or used directly as shown here.

LoadGameBP_3.png