๐พ Snapshots¶
Save/load helpers for inventory + equipment state.
InventorySnapshotsโ capture, serialize, deserialize, and apply- DTOs โ JSON-serializable data only
- Policies โ skip unknown items or substitute placeholders
๐ Quickstart¶
// Capture
var dto = InventorySnapshots.Capture(characterInventory, characterEquipment);
// Save
InventorySnapshots.SaveToFile("mysave", dto);
// Load
var loaded = InventorySnapshots.LoadFromFile("mysave");
// Apply
if (loaded != null)
{
InventorySnapshots.Apply(
characterInventory,
characterEquipment,
loaded,
myItemDatabase,
InventorySnapshotOptions.Default
);
}
๐ Capture always snapshots both the InventoryContainer and the EquipmentContainer.
๐ Versioning¶
Every snapshot includes:
{
"version": 1,
"inventory": { "slots": [...] },
"equipment": { "slots": [...] }
}
- Current format: version = 1
- Reserved for future migrations (new fields or format changes)
๐ Missing Item Policy¶
When applying a snapshot, unknown item GUIDs are handled according to
InventorySnapshotOptions.policy.
Skip¶
- Drops the item entirely
- Logs a warning in the Editor
SubstitutePlaceholder¶
- Replaces the item with
ItemDatabase.missingPlaceholder - Falls back to Skip if no placeholder is assigned
When substitution occurs, the original GUID is preserved as metadata:
{
"guid": "unknown123",
"quantity": 1,
"meta": [
{ "key": "originalGuid", "value": "unknown123" }
]
}
๐งช Apply Behaviour¶
Inventory¶
- Target container is cleared, then repopulated
- Only the first
container.Slots.Countentries are applied - Extra snapshot slots are ignored
Container size is defined by CharacterInventory + policies, never by the snapshot.
Equipment¶
- Equipment container is cleared, then repopulated by slotId
- Quantities are always forced to 1
- Snapshot entries with unknown slotIds are skipped
Events¶
- Both containers use
DeferEvents()during restore - Apply triggers at most one
OnChangedevent per container SceneInventoryServicedoes not emit deltas during Apply unless counts change after binding
๐ Files & Storage¶
Snapshot JSON files are written to:
Application.persistentDataPath/REV_<name>.json
- Filename prefix:
REV_ - Prevents collisions and accidental user edits
โ ๏ธ Gotchas¶
- Equipment quantities are always restored as
quantity = 1 - Snapshots never resize containers โ use policies or
CharacterInventory.backpackSize - Unknown items require
MissingPlaceholderfor substitution - Deep copies โ all stacks and metadata are cloned on capture
- DTOs contain primitives only โ no live object references