Skip to content

04 — Snapshots

Goal:
Show how to capture, save, and restore complete inventory (and optionally equipment) state at runtime.


Purpose

Demonstrate how InventorySnapshots can serialize full inventory and equipment state to JSON,
then safely restore it in-game — a foundation for autosaves, persistence systems, or quick developer backups.


🎓 What This Scene Teaches

  • Capturing snapshots with InventorySnapshots.Capture(...).
  • Saving/Loading snapshots to JSON files under Application.persistentDataPath.
  • Restoring inventories (and optional equipment) safely.
  • Handling missing items via placeholder substitution.
  • Clearing and autosaving inventory programmatically.

🧩 How to Use

  1. Assign several ItemDefinitions and click Give to populate your Backpack.
  2. Set a Snapshot Name (e.g. snapshot_01).
  3. Click Save to persist the current inventory (and optionally equipment).
  4. Click Load to restore the saved state.
  5. Toggle Include Equipment to back up equipped items too.
  6. Toggle Placeholder Missing to replace unknown GUIDs with your database’s placeholder item.
  7. Try Clear to empty everything, then Load again to confirm persistence.
  8. Optionally use Autosave to test quick backups.

💡 Key Takeaways

  • Snapshots are stored as plain JSON for easy debugging and modding.
  • Equipment and Inventory are both serialized, respecting slot IDs, filters, and equipment quantity rules (always 1).
  • The system automatically tags substituted items with originalGuid metadata when placeholders are used.
  • Works seamlessly with ItemDatabase.MissingPlaceholder.
  • All writes are wrapped in DeferEvents() to avoid redundant UI refreshes.

🔧 Scene Setup

Component Purpose
InventorySnapshotsPanel Teachable overlay demonstrating capture, save, and load operations.
SceneInventoryService Central service managing containers and database access.
CharacterInventory Holds the “Backpack” container for items.
CharacterEquipment (optional) Adds equipped item persistence.
InventoryAuthorityBinder Optional baseline authority binder (default allow; toggle off to simulate NoAuthority).
Property Default Notes
Container "Backpack" Configurable on the panel.
Toggle Key Backquote (```) Shows/hides the panel overlay.

Scene Path:
Assets/RevFramework/Runtime/Systems/Inventory/Samples/Scenes/04_Snapshots/


📝 Notes

  • Files are written to:
    Application.persistentDataPath/tdk_<snapshotName>.json
  • In Editor, Reveal Snapshot and Open Folder buttons use EditorUtility.RevealInFinder().
  • When MissingItemPolicy.SubstitutePlaceholder is enabled, missing items are replaced at load and logged in the Console.
  • Designed for save/load systems, autosaves, and testing persistence logic.
  • Runs standalone — no dependency on Crafting, Currency, or other systems.
  • Snapshot capture and restore operate directly on inventory and equipment containers.
  • These operations are not authority-gated by default and are intended to be invoked from authoritative gameplay code (e.g. server-side save/load flows).
  • If no binder is present, service-level mutations still default to allowed (single-player friendly).