Remote Storage

Installation

  • Complete the steps in Getting Started if LionSDK is not installed.

  • If LionSDK is already installed,

    • Install the package Lion - Remote Storage .

Quick Start

  1. Setup Firebase.

  2. Setup Firestore.

    1. If integrated, users will be able to retrieve game data even after reinstall.

  3. Setup Facebook Authentication (Optional, but recommended, if you want Facebook login data sync)

    1. If integrated, users will be able to retrieve game data from their other devices, too, after Facebook login.

When to use?

What it is: Cloud‑backed key–value store with cross‑device sync. Optional Facebook Login for identity; otherwise uses device‑scoped IDs.

When to use it: You want user data to survive reinstalls and sync across devices.

Good for: Cross‑device progression, restore after reinstall, server‑adjacent features.

Pros

  • Persists across reinstalls and devices

  • Built‑in merge/conflict handling (via MergeConflictData)

  • Works with social platforms (like Facebook)

  • Non‑blocking β€” does not delay game startup

Cons

  • Requires Firebase project setup

  • Network latency and offline retry logic apply

How It Works (Architecture Overview)

Remote Storage uses a local‑first architecture. All reads and writes go to local storage (PlayerPrefs) instantly. Cloud synchronization with Firestore happens in the background, so it never blocks your game.

Game Code β†’ LionStorage API β†’ LocalStorage (PlayerPrefs) β†’ instant reads/writes
                                         ↕
                               CloudSyncManager (background)
                                         ↕
                                  Firestore (cloud)

Initialization Flow

  1. Initialize() loads data from PlayerPrefs immediately and returns without waiting for the cloud.

  2. Background sync starts: Firebase Email/Password auth β†’ pull remote data β†’ merge β†’ push.

  3. Remote Storage does NOT block LionSDK initialization.

IsDataReady behavior differs by session type:

  • Returning user (local data exists): IsDataReady = true immediately β€” local data is playable right away.

  • First session (no local data): IsDataReady = true only after the background cloud sync completes (or fails). Show a loading indicator until ready.

Background Cloud Sync

Once initialized, the system automatically pushes data to Firestore:

  • Sync Interval Seconds β€” pushes every 30 seconds by default (configurable via _syncIntervalSeconds on the Firestore ScriptableObject in the Inspector).

  • Sync On Application Pause β€” pushes when the app is paused/backgrounded (enabled by default).

You do not need to push data to the cloud manually. The package system auto-syncs data to the cloud in the background.

SyncState API

Use the SyncState API to monitor the current status of the cloud synchronization.

SyncState Enum

State
Description

LocalOnly

No cloud connection (initial state, or auth failed).

Authenticating

Firebase email auth is in progress.

Syncing

Pulling or pushing data to Firestore.

Synced

Cloud and local data are in sync.

Failed

Auth or sync failed. Local data is safe and playable.

Checking Current State

if (RemoteStorage.CurrentSyncState == SyncState.Synced)
{
    Debug.Log("Cloud data is in sync!");
}

Subscribing to State Changes

RemoteStorage.OnSyncStateChanged += (state) =>
{
    Debug.Log($"Sync state changed: {state}");
    
    if (state == SyncState.Failed)
    {
        // Show offline indicator to the player
    }
};

Using the OnDataMergedFromCloud Event

When data is synced from the cloud, a merge conflict may occur between local and remote data. If the remote data wins (because it has a more recent purchase, higher XP, or newer save time), the local data is replaced.

When this happens, LionStorage.OnDataMergedFromCloud fires so your game can reload its in‑memory state.

LionStorage.OnDataMergedFromCloud += () =>
{
    // Cloud data replaced local data β€” reload your in-memory state
    coins = LionStorage.GetInt("coins", 0);
    volume = LionStorage.GetFloat("volume", 1f);
    playerProfile = LionStorage.GetValue<PlayerProfile>("profile", new PlayerProfile());
};

RemoteStorage Static API

Member
Type
Description

IsInitialized

bool

true once the module has completed initialization (local data loaded).

OnInitialized

event Action

Fires when initialization completes.

CurrentSyncState

SyncState

Current cloud sync state.

OnSyncStateChanged

event Action<SyncState>

Fires when sync state changes.

CurrentMergeConflictData

MergeConflictData

The current merge conflict data from the active storage, or null.

Last updated

Was this helpful?