Custom Saving/Loading

It is quite easy to expand upon the existing save/load system, thanks to our Save & Load Manager and the power of Instanced Structs!

Lets demonstrate this with a few examples.

Example 1.0 - Saving a Custom Property

For this example, we're going to add a new variable to our Character blueprint (B_Soulslike_Character). You can also add it to any component you want.

Next, we'll add some example events to alter/view its value:

Now to save this variable, all we need to do is trigger the RequestAddToSaveData() message in our Player Controller (PC_SoulslikeFramework):

This message has 2 inputs. It might look a bit overwhelming at hindsight. However it provides a great amount of modularity when it gets to saving/loading data:

  1. Save Tag (Gameplay Tag): Tag used for tracking save entry. Can be used to find data by tag and/or update/remove save entry data.

  2. Data[] (Instanced Struct): The actual data that is going to be saved/loaded.

In our case, we'll create an array which contains a single element - the value of our new property "MyVariable". This will update our save data and trigger an autosave whenever we change this value. We should also make the saving part a custom event if we want to call it from anywhere else.

Finally, there are 2 methods in AC_SaveLoadManager that we need to adjust:

  1. SerializeDataForSaving(): Serializes a specific data by tag and adds it to the final save data.

Rough example - the cast can be avoided.
  1. SerializeAllDataForSaving(): Serializes all possible data and sets it to the final save data.

Rough example - the cast can be avoided.

You're all set! Now our new property will get saved whenever it's value has changed. Additionally, it will also get saved whenever we bulk-save data (specifically on quits/crashes etc).

Example 1.1 - Loading our Custom Property

Loading the saved data is as easy as this:

The decimal difference is related to formatting.

Example 2.0 - Saving Custom Actor(s)

For this example, we're going to create an actor which adjusts its scale when player overlaps its trigger. Then we'll save its "overlapped" state and new scale.

Lets start by creating a new actor and setting it up accordingly:

Next, we'll need a new Struct to keep track of the 3 properties this actor has:

  1. Id (GUID): the unique identifier of the actor (important)

  2. Scale (Vector): the 3d scale of the actor

  3. HasBeenOverlapped (Bool): the state of the actor

And now, when the timeline for scaling up is finished, we can request to update the save data with the new entry:

Finally, ensure that the actor instance you want to save in your world/level has a valid GUID:

That's it! Now we're saving this actor.

Example 2.1 - Loading our Custom Actor(s)

To load, we just need to adjust our Event BeginPlay slightly and bind to AC_SaveLoadManager's OnDataLoaded() delegate:

That's basically it. Now when you play, you'll notice that this actor now saves its properties!

Last updated

Was this helpful?