InventorySave and Load
Last modified: 26 September 2024Saving the Inventory
To save the Inventory, you need to use the NinjaInventorySaveGame
class, which is able to serialize the Inventory Manager's properties, along with all Containers, Items and their Fragment Memories.
It's important to call the SaveInventory
function, providing the Inventory Manager that you want to save. This is the function responsible for obtaining the serialized inventory data and adding it to the save file.
Here is an example of how to perform a save operation.
Loading the Inventory
To load the Inventory, once again you need to use the `NinjaInventorySaveGame` class, which is able to deserialize the Inventory Manager's properties, along with all Containers, Items and their Fragment Memories.
Here is an example of how to perform a load operation.
Data Serialization
The following image shows what a serialized and saved inventory looks like, from a data structure perspective.
tip
The data view for the serialized inventory structure was obtained using the Save File Editor plugin, by Hubber Studios. For more information, please check the links below.
As you can see, it contains all containers, items and their memories from the provided Inventory Manager. They can be used to restore the inventory to that exact state.
The Serialization and Deserialization processes are separate from the actual Save and Load. This allows you to use the serialized structure for any purposes you might need, and even replace the entire saving mechanism with your own.
You can obtain the Serialization structure by calling the GetInventoryRecordForSerialization
function, available in the Inventory Manager. It will provide a FInventoryManagerRecord
struct, containing all the data displayed in the example above.
You can also load an Inventory Manager Record back into the inventory, by calling the LoadInventory
, which resets the inventory data and loads the one provided by the incoming FInventoryManagerRecord
.