Ninja Bear Studio Plugins Help

Save and Load

Saving the Inventory

To save an inventory, use the NinjaInventorySaveGame class. This class can serialize the Inventory Manager's properties, along with its Containers, Items, and their Fragment Memories.

Call the SaveInventory function (defined in the NinjaInventorySaveGame object) and pass the Inventory Manager you want to save. This function gathers the current inventory state and stores it in the Save Game Object, which can then be saved using Unreal Engine's standard save flow.

The following example will walk you through these general steps. It's done using a debug key in the Player Character blueprint, but you can perform the save operation wherever it is appropriate for your game.

Saving the Inventory

Saving the Player Inventory
  1. Retrieve and validate the Inventory Manager Component from your actor using GetInventoryManager, available in the Inventory Blueprint Library.

  2. Create a Save Game Object using NinjaInventorySaveGame as the Save Game Class.

  3. Call SaveInventory on the Save Game Object, passing in the Inventory Manager to be serialized.

  4. Perform an asynchronous save operation, providing the desired slot and user index.

  5. Optionally track the result (e.g., print a message or update UI elements).

You can verify the generated save file using any tool, such as the Save File Editor, available on Fab.

Next, we'll look into the loading operation, which can be executed either automatically or manually.

Loading the Inventory

Once a saved inventory file exists, it can be loaded back into the Inventory Manager using the same base classes and functions used during saving.

The loading process can be performed either manually (e.g., triggered by the player or game logic) or automatically (during initialization). The example below demonstrates a manual approach using a debug key in the Player Character blueprint.

To load the data, you need to call the LoadInventory function from a NinjaInventorySaveGame object after successfully loading it from disk.

Loading the Inventory

Loading the Player Inventory
  1. Use GetInventoryManager to retrieve the Inventory Manager for the actor that should receive the inventory state.

  2. Validate the returned reference with Is Valid. If it is not valid, skip the rest of the logic.

  3. Obtain the slot name and user index from the Inventory Manager using Get Save Game Slot Name and Get Save Game User Index.

  4. Call Async Load Game from Slot, passing in the slot name and user index retrieved above.

  5. Check the success of the operation, and cast the returned object to NinjaInventorySaveGame.

  6. Call LoadInventory on the Save Game object, providing the Inventory Manager reference. This will apply the saved Containers, Items, and Fragment Memories to the manager.

  7. Optionally track the result (e.g., print a message or update UI elements).

Automatic Loading

The Inventory System also supports automatic loading of saved data, which can occur during the initialization of the Inventory Manager, without requiring any manual logic.

This behavior is controlled by the following Inventory Manager settings:

Property

Description

bAutomaticallyLoadFromDisk

If enabled, the Inventory Manager will automatically attempt to load inventory data from disk when it is initialized.

SaveGameSlotName

The name of the slot to load from. This value is also used during save operations. You can retrieve it at runtime using GetSaveGameSlotName.

SaveGameUserIndex

The user index to load from. You can override GetSaveGameUserIndex to implement dynamic logic if needed.

If a save file is present for the specified slot and index, the inventory will be automatically restored—no extra calls are needed. If the file is missing, the initialization happens normally, potentially loading default items as needed.

This setup is ideal for player inventories that should persist across sessions or respawns, without requiring explicit save/load Blueprint logic during gameplay.

Last modified: 23 July 2025