ComboMeter - Save Function

ComboMeter - Save Function

Overview

The Game Save functionality provided with the ComboMeter plugin let's you save arbitrary numeric data per Level per Difficultiy Setting. The numeric data can be anything - Rank the player achieved, Orbs collected, number of deaths. There is no limitation on what you can save as long as it's a numeric(float to be specific) data.

The Difficulty setting and Levels are also dynamic, meaning you can have any difficulty settings such as the most common Easy, Normal and Hard or more exotic - Just the Story, Story and Sword  etc like in The Witcher 3 game. The Levels are also dynamic and you can name it however you like as long as you are consistent between saves.

Save Function Workflow

Create a default save game when the game begins

When the user has just started your game, create a default save game with the list of Missions(same as Levels discussed above) and Difficutly Settings using the CreateDefaultSaveData. This just creates a empty save file with the Missions and Difficulty Settings you provided. That is, for each Difficulty Setting a Mission data will be created but without any actual save data.

You can see in the video that, I first checked if a save data was available. If there is no prior save data, the CA_LoadSaveGame will execute the LoadError pin. So when the LoadError pin is executed, you can be certain that this is the first time the user has started the game and create the default save game. Otherwise, the save file from the given slot will be loaded and LoadSuccess pin will be executed.

Saving a Stat

Now that you have a Save file that you can save to, let's save something in it. Assume that the player has completed a mission on a particular difficulty and you have the Rank the player achieved saved in a float variable. You can save this Rank data in the save file you created in the previous step by using the SetStat function on the save file. The function receives the Stat name and value to be saved along with the Mission/Level name and the Difficulty setting. This just the data on the save file. You will have to save to actually persist this data. To save the Gamesave, use the CA_SaveGame function. This internally uses the same SaveGame function that Unreal provides. But prefer using CA_SaveGame instead of the one provided by Unreal. This would help in the future if any additional work is to be performed from the library.


In the video, the RANK  is saved in the EventBegin itself. This is just for demonstration purpose. In your actualy game you would trigger the save at the end of the mission.

Showing Saved Data

Now that you have both the GameSave created and some data saved in it, it's time to show the data to the user. You would usually do this when the user wishes to see his past data of a particular Mission on a particular Difficulty.


The plugin provides two widgets for this purpose - SaveViewWidgetBase and SaveViewWidgetItemBase.

The SaveViewWidgetBase widget is basically the container that shows all the individual Mission data for a particular Difficulty setting. This manages showing the individual Mission data, animation etc

The SaveViewWidgetItemBase widget is child widget of the SaveViewWidgetBase that receives the individual Mission data from the SaveViewWidgetBase which then can be used by the SaveViewWidgetItemBase to show the Stats you have saved.

For example, let's say you have 3 Missions. You create a SaveViewWidgetBase and then you set the SaveViewWidgetItemClass on this. Then SaveViewWidgetBase widget when Activated will create three instances of SaveViewWidgetItem, one for each Mission, and pass the appropriate Mission data to the individual instance of the SaveViewWidgetItem. Now the individual instances of SaveViewWidgetItem can access this data using the GetStat method to access the data passed to it and show it on the UI.

All of this is already provided in the plugin itself. So familiarizing with these examples would help you create your own widgets.


Again, for demonstration purpose, the data is shown immidiately when the save file is found in the example video. In an actual game, you would want to show the data when the player wishes to see it.

Saving Rank data

As discussed previously, you can save any arbitrary numeric data you wish to the save file. In the example video, you can see that RANK stat is added by the PlayerController blueprint  to the game save and then saved to the disk.

Once the save is successful and you restart the game in the editor, you can see that when the SaveViewWidgetBase  is activated, you can see the saved RANK stat shown on the UI. This is because if you look at the example SaveViewWidgetItem widget provided, it accesses the RANK stat from the data passed to it shows it. If you want to save and show any other data, say ORBS, you will have to do the same as RANK - save it in the PlayerController BP and access it in the SaveViewWidgetItem widget.

Remember that while saving you will have to pass the correct Difficulty setting and the Mission name. You would have to save these two in some variables and pass it to the SetStat function.

Customizing Widget Display

The SaveViewWidgetBase  and SaveViewWidgetItemBase provide a few options to customize the display of the saved data. 

InitAnimation on the SaveViewWidgetItemBase lets you play the provided animation when each of the child widget is added to the screen.

Rows lets you control how many rows are displayed. The colums are automatically adjusted based the number of rows and the number of Missions you have provided.

You should be now comfortable enough to save any arbitrary Stats you want to the disk. I recommend you to go through the examples provided in the plugin to familiarize with the Save function. You can copy the blueprints out of the plugin and consume it directly as well with any modifications as necessary.