Configure PersistlyGameSaves during boot with the Unity settings asset or startup code.
Unity Templates
Unity templates for one-save, slots, account restore, and connect-later.
Use PersistlyGameSaves from Unity gameplay code first. Start with SaveDataAsync for one current save, move to SaveSlotAsync for named slots, restore known account sessions through AttachAccountAsync, or connect anonymous progress to Firebase, Supabase, or Auth0 later.
One Save
Unity one-save starter
When to use this: Use this for Unity games that need one durable autosave path first.
Unity starter
Unity one-save starter
Copy this into your game-facing save service, then adapt the data type and safe sync moments to your game.
using Persistly.Unity;
using UnityEngine;
public sealed class SaveService : MonoBehaviour
{
public async void Save(GameState state)
{
await PersistlyGameSaves.Shared.SaveDataAsync(state);
}
public async void Load()
{
var loaded = await PersistlyGameSaves.Shared.LoadDataAsync<GameState>();
if (loaded.Found && loaded.Data != null)
{
ApplyData(loaded.Data);
}
}
public async void SyncCheckpoint()
{
await PersistlyGameSaves.Shared.ForceSyncDataAsync();
}
}Save normal gameplay state with SaveDataAsync.
Force-sync from checkpoint, pause, or manual-save moments.
Read the SDK setup, behavior, and facade guidance for this engine.
Open SDK docsDetailed guideOpen the matching SDK guide for save, load, sync, and account restore details.
Open guideTemplate folderOpen the public SDK repository folder for the complete copy-paste template when it is published.
Open GitHubMultiple Slots
Unity multiple-slot starter
When to use this: Use this for manual saves, campaigns, and character select screens in Unity.
Unity starter
Unity multiple-slot starter
Copy this into your game-facing save service, then adapt the data type and safe sync moments to your game.
using Persistly.Unity;
using UnityEngine;
public sealed class SlotSaveService : MonoBehaviour
{
public async void SaveSlot(string slotId, GameState state)
{
await PersistlyGameSaves.Shared.SaveSlotAsync(slotId, state, new PersistlySaveSlotOptions
{
SlotInfoJson = "{"label":"" + slotId + ""}"
});
}
public async void LoadSlot(string slotId)
{
var loaded = await PersistlyGameSaves.Shared.LoadSlotAsync<GameState>(slotId);
if (loaded.Found && loaded.Data != null)
{
ApplyData(loaded.Data);
}
}
public async void SyncSlot(string slotId)
{
await PersistlyGameSaves.Shared.ForceSyncAsync(slotId);
}
}Use stable slot ids your game owns, not display names that change often.
Keep save-menu labels, playtime, and preview data in SlotInfoJson.
Sync only the slot the player changed unless your lifecycle calls for due sync.
Read the SDK setup, behavior, and facade guidance for this engine.
Open SDK docsDetailed guideOpen the matching SDK guide for save, load, sync, and account restore details.
Open guideTemplate folderOpen the public SDK repository folder for the complete copy-paste template when it is published.
Open GitHubAccount + Slots
Unity account + slots starter
When to use this: Use this when Unity account restore is backed by your own trusted sign-in system.
Unity starter
Unity account + slots starter
Copy this into your game-facing save service, then adapt the data type and safe sync moments to your game.
using Persistly.Unity;
using UnityEngine;
public sealed class AccountSlotService : MonoBehaviour
{
public async void ExportSessionForBackend()
{
var session = PersistlyGameSaves.Shared.GetAccountSession(includeToken: true);
SendToYourBackend(session.AccountId, session.AccountSessionToken);
}
public async void RestoreAccount(string accountId, string accountSessionToken)
{
await PersistlyGameSaves.Shared.AttachAccountAsync(accountId, accountSessionToken);
}
public async void SaveSignedInSlot(string slotId, GameState state)
{
await PersistlyGameSaves.Shared.SaveSlotAsync(slotId, state, new PersistlySaveSlotOptions
{
SlotInfoJson = "{"label":"" + slotId + ""}"
});
await PersistlyGameSaves.Shared.ForceSyncAsync(slotId);
}
}Treat accountSessionToken as a sensitive restore credential in your own account system.
Call AttachAccountAsync before loading a signed-in player's slots on a new device.
Keep gameplay code on SaveSlotAsync and ForceSyncAsync after account restore.
Read the SDK setup, behavior, and facade guidance for this engine.
Open SDK docsDetailed guideOpen the matching SDK guide for save, load, sync, and account restore details.
Open guideTemplate folderOpen the public SDK repository folder for the complete copy-paste template when it is published.
Open GitHubConnect Later
Unity anonymous-first connect-later starter
When to use this: Use this when Unity players can start immediately, save progress, and connect Firebase, Supabase, or Auth0 later.
Unity starter
Unity anonymous-first connect-later starter
Copy this into your game-facing save service, then adapt the data type and safe sync moments to your game.
using Persistly.Unity;
using UnityEngine;
public sealed class ConnectLaterSaveService : MonoBehaviour
{
public async void SaveBeforeSignIn(PlayerData state)
{
await PersistlyGameSaves.Shared.SaveDataAsync(state);
await PersistlyGameSaves.Shared.ForceSyncDataAsync();
}
public async void ConnectFirebase(string firebaseIdToken)
{
try
{
await PersistlyGameSaves.Shared.ConnectWithFirebaseTokenAsync(firebaseIdToken);
}
catch (PersistlyApiError error) when (error.Code == PersistlyErrorCode.AccountAuthConflict)
{
ShowAuthConflictChoicesUI(error.DetailsJson);
}
}
}Configure AnonymousFirst during boot so local saves work before sign-in.
Get provider tokens from your Firebase, Supabase, or Auth0 integration.
On AccountAuthConflict, keep local progress. Let the player retry with a different provider account or explicitly discard local Persistly state before using the existing provider-linked account.
Read the SDK setup, behavior, and facade guidance for this engine.
Open SDK docsDetailed guideOpen the matching SDK guide for save, load, sync, and account restore details.
Open guideTemplate folderOpen the public SDK repository folder for the complete copy-paste template when it is published.
Open GitHub