Skip to content

Storage (Unity)

FRVRSDK.Data is the Unity wrapper’s storage surface. The same namespace exposes two flavours:

  • Local storage (per device) — SetItem, GetItem, RemoveItem, RemoveItems, plus batch helpers SetItems / GetItems and whole‑blob helpers SetLocalJson / GetLocalJson.
  • Cloud storage (follows the player across devices) — SetCloudItem, GetCloudItem, RemoveCloudItem, RemoveCloudItems. No batch or JSON‑blob equivalents on the cloud side.

All methods are callback‑based. Under the hood values are stored as strings (the C# signature is object and .ToString() is called for you), and Get callbacks deliver object — cast to string to use. Serialize complex objects with JsonUtility.ToJson(…) before storing.

In the Editor, local and cloud storage persist to <Project>/Library/FRVRSim/local.json and cloud.json — survives playmode restarts and lives outside Assets/ so it isn’t imported.

FRVRSDK.Data.SetItem("coins", "100", result => Debug.Log($"set: {result}"));   // result == 1 on success

FRVRSDK.Data.GetItem("coins", value =>
{
    string coins = (string)value;   // callback type is Action<object>
    Debug.Log($"coins = {coins}");  // empty string when the key isn't set
});

FRVRSDK.Data.RemoveItem("coins", result => { /* result == 1 on success */ });

string[] stale = { "run_temp", "tutorial_seen", "dev_flag" };
FRVRSDK.Data.RemoveItems(stale, result => { });

Batch reads / writes (local only):

var batch = new Dictionary<string, object>
{
    { "coins", 100 },
    { "level", "tutorial_done" },
};
FRVRSDK.Data.SetItems(batch, result => { /* 1 on success */ });

FRVRSDK.Data.GetItems(new[] { "coins", "level" }, dict =>
{
    foreach (var kvp in dict) Debug.Log($"{kvp.Key} = {kvp.Value}");
});

Use local storage for:

  • Preferences (“muted”, “preferred_hand”)
  • Caches the player can afford to lose (temp run state, asset caches)
  • Device‑specific settings
string saveJson = JsonUtility.ToJson(gameState);
FRVRSDK.Data.SetCloudItem("save", saveJson, result => Debug.Log($"saved: {result}"));

FRVRSDK.Data.GetCloudItem("save", value =>
{
    string json = (string)value;          // Action<object> — cast to string
    if (string.IsNullOrEmpty(json)) return;
    var state = JsonUtility.FromJson<GameState>(json);
    LoadState(state);
});

FRVRSDK.Data.RemoveCloudItem("save", result => { });

string[] keys = { "save_v1", "legacy_key" };
FRVRSDK.Data.RemoveCloudItems(keys, result => { });

Use cloud storage for anything the player will notice losing: save game, unlocks, IAP‑granted content.

Treat a missing cloud read as “unknown”, not “new user”

Section titled “Treat a missing cloud read as “unknown”, not “new user””
FRVRSDK.Data.GetCloudItem("save", value =>
{
    string json = (string)value;
    if (string.IsNullOrEmpty(json))
    {
        // Could be: a genuinely new player, OR auth isn't ready yet.
        // Wait a frame and retry before overwriting with fresh state.
    }
});