# Save and Restore an Inventory

> For the complete documentation index, see [llms.txt](llms.txt).

Save a character with a partially used stack, move it, then load the save and check where it returns. The save contains the inventory's containers, items, and fragment memories, including stack counts and placement.

Procedure: Save the player's current inventory

1. After the Inventory Manager has initialized, create a Save Game Object using `NinjaInventorySaveGame`. Call `SaveInventory` on it with the manager that owns the player's items.

2. Get Save Game Slot Name and Save Game User Index from that manager. Pass those values and the object to Async Save Game to Slot. Show the player a saved message only when the disk operation succeeds.

![Copying the manager's inventory into a Save Game object and writing it to a slot](Documentation/inv_advanced_save.png)

Procedure: Restore the same player

1. For a manual load, read the same slot and user index with Async Load Game from Slot. Check the result and cast the returned object to `NinjaInventorySaveGame`. Call `LoadInventory` on it with the target manager. Restoring into a running inventory replaces its current contents.

2. For automatic restoration at startup, enable Automatically Load From Disk on the manager and configure the same slot and user index. If no save exists, the manager uses its starting inventory. Use a separate test slot if you want to keep an existing playthrough.

Override the manager's `GetSaveGameSlotName` or `GetSaveGameUserIndex` when each player or profile needs a different save. In multiplayer, run the normal save and restore flow for the authoritative inventory. Bind `OnInventoryInitializationSucceeded` to reopen the inventory UI after initialization and `OnInventoryInitializationFailed` to handle a failed initialization.

When a custom fragment needs to change how it saves a value, override `SerializeFragmentMemory` and read the result in `InitializeItemWithDefaultMemory`. For a rechargeable tool, save its remaining charge and verify that it survives a round trip.

## Try It in Play

Move a partial bandage stack to a known slot and save. Use one bandage and move the stack elsewhere. Load the save and check its original quantity and position. With a spatial backpack, save a rotated tool and check its footprint after loading. With equipment, save the lantern in its slot and check its attachment and state after the restore.

