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.

Prerequisites
How-To: Get the Building Blocks. This plugin depends on no save system at all. It exposes plain 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 fieldContents
LayoutAssetThe layout asset reference.
NextEntryIdSo restored entries keep their ids and new ones never collide.
ItemsFCrimsonInventorySaveEntry per entry: ItemDef, StackCount, EntryId, SlotIndex, GridPosition, Rotation, LayoutGroupId, LockFlags, EquippedSlotTag, EquippedSlotIndex, StatTags, FloatStatTags, StateFragments.
ActiveConstraintsOne FCrimsonInventoryObjectSaveRecord (class path + SaveGame bytes) per constraint object.
ConstraintMaxTags / ConstraintMaxFloatTagsThe 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.
CurrencyAmountsFCrimsonInventoryCurrencyKey (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.

Verify
Save with 3 entries, one locked, one with durability 40: the struct's 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.

Verify
Play As Client after a restore: the client shows the same slots, counts, and durability, and 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