How-To: Save and Restore
Goal: serialize an inventory - entries, placement, lock flags, per-instance state, constraints, caps, currencies - into a plain struct you store however you like, and restore it on the server.
USTRUCTs through GetSaveData / ApplySaveData, and you persist them with whatever you already use - a USaveGame, your own serializer, or a save fragment you write.1. What the save struct contains
FCrimsonInventorySaveData field | Contents |
|---|---|
LayoutAsset | The layout asset reference. |
NextEntryId | So restored entries keep their ids and new ones never collide. |
Items | FCrimsonInventorySaveEntry per entry: ItemDef, StackCount, EntryId, SlotIndex, GridPosition, Rotation, LayoutGroupId, LockFlags, EquippedSlotTag, EquippedSlotIndex, StatTags, FloatStatTags, StateFragments. |
ActiveConstraints | One FCrimsonInventoryObjectSaveRecord (class path + SaveGame bytes) per constraint object. |
ConstraintMaxTags / ConstraintMaxFloatTags | The capacity caps only. The current counters are not saved: ApplySaveData recounts them from the restored entries, so they can never drift from what the inventory actually holds, and the recount announces the real values through OnConstraintValueChanged. |
CurrencyAmounts | FCrimsonInventoryCurrencyKey (table path + row) -> amount. |
State fragments serialize only their SaveGame properties into FCrimsonInventoryObjectSaveRecord::Bytes; after restore each fragment receives OnStateRestored (Lifetime uses it to resume its timer). Constraints get OnStateRestored too.
2. Save
Server: Get Save Data on the manager returns the struct; store it in a SaveGame-flagged variable of your SaveGame object. Get Save Data on the routing component returns FCrimsonInventoryRoutingSaveData for personal containers.
Items has 3 rows, LockFlags = 1 on the locked one, and the durability fragment record has non-empty Bytes.3. Restore
Server: Apply Save Data on the manager (it clears the current contents first), then Apply Save Data on the routing component, then Try Flush Pending Equips if you use the equipment bridge.
InventoryUpdated fired once.See also
- How-To: Bridge to Equipment
- How-To: Route UI Requests (personal containers)
- Concept: Multiplayer for where each half of a restore runs