Skip to content

๐Ÿ’พ 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.Count entries 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 OnChanged event per container
  • SceneInventoryService does 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 MissingPlaceholder for substitution
  • Deep copies โ€” all stacks and metadata are cloned on capture
  • DTOs contain primitives only โ€” no live object references

  • Data โ†’ ItemDefinition, ItemDatabase, placeholders
  • Services โ†’ container creation, sizing, authority
  • UI โ†’ debug snapshot panels