Skip to content

RevFramework – Sample Scene: 03_Currency_Persistence

Namespace: RevGaming.RevFramework.Runtime.Currency.Samples.Scenes


🎯 Purpose

Demonstrate how to save and restore wallet data using JSON files, and how to inspect audit history for recent currency operations.
This scene combines CurrencyPersistence with AuditedCurrencyService to show full traceability of economic state.


🧩 What This Scene Teaches

  • How to capture and restore wallet states via CurrencyPersistence.
  • How StableId components provide persistent wallet identity.
  • How to serialize and deserialize wallet data using CurrencyJsonSave.
  • How to inspect per-owner audit logs recorded by AuditedCurrencyService.
  • How to filter audit history by owner, operation type, and currency.

🕹️ How to Use

  1. Enter Play Mode.
  2. Open the CurrencyPersistenceAuditPanel (F8).
  3. Press Save Now to capture all wallet balances to JSON under
    Application.persistentDataPath (default file: wallets_demo.json).
  4. Modify balances using another panel or scene logic.
  5. Press Load Now to restore all wallets exactly as they were saved.
  6. Switch to the Audit section:
  7. Navigate owners using < / > arrows.
  8. Filter by operation type (Set, Credit, Debit, Transfer).
  9. Filter by currency to isolate specific histories.

🔐 Authority (Important)

This sample scene includes a CurrencyAuthorityBinder configured for single-player use:

  • CurrencyAuthorityBinder
  • alwaysTrue = true

This allows all currency mutations so the demo works out of the box.

Why this exists

RevFramework currency mutations are authority-gated by default.

  • If no authority is present, all mutations are blocked.
  • This is intentional and required for multiplayer safety.

Multiplayer note

For multiplayer or server-authoritative games:

  • Do not use CurrencyAuthorityBinder
  • Implement your own ICurrencyAuthority
  • Validate all currency mutations on the server/host

This scene uses the permissive binder only to demonstrate behaviour in a local, single-player context.


💡 Key Takeaways

  • Persistence works for any object with a StableId — no manual mapping required.
  • Save/load operations are atomic and rollback-safe.
  • Audit entries provide complete traceability (reason, sourceId, timestamp).
  • JSON snapshots are human-readable for debugging or version control.
  • Ideal for save/load systems, offline wallets, or developer economy debugging.

⚙️ Stack Composition

Bootstrap: CurrencyServiceBootstrap
Service Stack:
SceneCurrencyService → CappedCurrencyService → AuditedCurrencyService → AuthorityCurrencyService

(Authority provided by CurrencyAuthorityBinder for single-player demos.) Teaching Panel: CurrencyPersistenceAuditPanel
Supporting Components:
- CurrencyJsonSave (save/load driver)
- StableId (persistent identifier)
- CurrencySet (optional currency registry)

Scene Path:

Assets/RevFramework/Runtime/Systems/Currency/Samples/Scenes/03_Currency_Persistence/


⚠️ Gotchas

  • Ensure every wallet-bearing object has a StableId — missing IDs are skipped silently.
  • The JSON file path is per-user, under Application.persistentDataPath.
  • If you edit the JSON file manually, invalid entries will be ignored but logged as warnings.
  • Restores trigger audit entries by design — this preserves change history.
  • Large-scale games may want to implement async I/O for save/load operations.
  • If this scene is running the bootstrapped service stack, removing CurrencyAuthorityBinder will cause all mutations to fail with Unauthorized.

  • 02_Currency_Exchange — Conversion and transaction systems.
  • Persistence — Full technical breakdown of save/load APIs.
  • CoreCurrencyAudit, CurrencyTxn, and CurrencyFactories.
  • DecoratorsAuditedCurrencyService implementation.
  • Samples Index — Overview of all Currency sample scenes.