Unity Create Load Sync

Create once, then load and sync by explicit saveId.

This is the canonical Unity client flow. Create the save once, persist saveId locally, then treat load and sync responses as the canonical server snapshot.

Reference Example

Use this as the base Unity integration pattern.

using Persistly.Unity;

var client = new PersistlyClient(new PersistlyClientOptions(
    "https://api.persistly.app",
    "ps_test_..."
));

var created = await client.CreateSaveAsync(new PersistlyCreateSaveRequest(
    stateJson: "{\"coins\":418,\"checkpoint\":\"vault\"}",
    metadataJson: "{\"characterName\":\"Ayla\",\"slotLabel\":\"Beacon-A\"}",
    externalUserId: "player-184"
));

var loaded = await client.LoadSaveAsync(created.SaveId);

var result = await client.SyncSaveAsync(created.SaveId, new PersistlySyncSaveRequest(
    stateJson: "{\"coins\":612,\"checkpoint\":\"reactor\"}",
    baseVersion: loaded.Version,
    metadataJson: loaded.MetadataJson
));

if (result.Status == PersistlySyncStatus.Accepted)
{
    var canonical = result.Save;
}

Behavior

These are the runtime guarantees the Unity SDK preserves.

PersistlyClient caches canonical saves in memory, so sync can infer baseVersion after a create or load in the same process.

PersistlySyncResponse.Status is a real enum: use PersistlySyncStatus.Accepted and PersistlySyncStatus.Conflict, not magic strings.

Create, load, and sync always return the canonical server snapshot as a PersistlySave.

Conflict responses preserve the canonical save and typed conflict details so Unity projects can reconcile intentionally.