Drone Model & Game Template (GameInstance & SaveData)

This section explains how to share and save changes made to the “Drone Model & Game Template” configurator sold in the UE Marketplace between Levels.

Configurator changes are shared between Levels

About GameInstance

Use GameInstance to share configurator changes between Levels.This section explains how to create and incorporate GameInstance.

GameInstance Blueprint Creation

The GameInstance blueprint specifies the GameInstance class as its parent. The GameInstance blueprint created is named “DroneGameInstance”.

Specify GameInstance class as parent

Specify the GameInstance blueprint created in the project settings

“Project Settings” -> “Maps & Modes” -> “Game Instance Class” to the GameInstance blueprint you created.

Change Game Instance Class to DroneGameInstance

Added variables and functions to store in GameInstance

Add the [TypeNo] and [ColorNo] variables and the [saveData] function to the DroneGameInstance.

Obtaining a GameInstance

Add logic to acquire a GameInstance to the BeginPlay event of “CM_MaterialComponent”. Cast the acquired GameInstance to DroneGameInstance and store it in a variable.

Save configurator changes to GameInstance

In “ChangeMaterial” of “CM_MaterialComponent”, call the “SaveData” function of “DroneInstanceGame” to save the changes.

Check transitions between Levels

Add a “Go to race map” button to the configurator and change it to transition to the race map and check that the changes have been carried over.

Configurator screen
Change Type and Color
Go to race map

Save Changes

About SaveGame

GameInstance changes are discarded when the game is over. Therefore, if you want to keep the changes in the configurator after the game is over, you need to save them physically.

SaveGame Blueprint Creation

The SaveGame blueprint specifies the SaveGame class as its parent. The SaveGame blueprint created is named “DronSaveGame”.

Specify SaveGame class as parent

Added variables and functions for saving to SaveGame

Add [TypeNo] and [ColorNo] variables to DroneSaveGame.

Add Load logic

Add “Init” event to “DroneGameInstance” and add logic to load saved data. If it exists, cast to DroneSaveGame, get “TypeNo” and “ColorNo” from SaveGame, and set them as the initial values of DroneGameInstance. The created or retrieved DroneSaveGame is saved in a variable.

Add Save Logic

Add save logic to the “SaveData” event of the “DroneGameInstance”. Set the values of “TypeNo” and “ColorNo” in “AsDroneSaveGame”, then use “Save Game to Slot” to save the game.

Check SaveGame

After changing the colors in the configurator, exit the game and check to see if the changed values are carried over when the game is restarted.

Configurator screen
Change Type and Color
Restart after Game ends