Skip to content

Save to a cloud or a console save API

Goal: your game’s save lives in a place you control, such as a cloud service, a console’s save API or your own database, and not in the Save System’s slot files.

If you only want the slot files somewhere else, a custom storage is less work and keeps the slot list. This recipe is for when you hold the bytes yourself, because a platform asks for its own save API, because you sync saves to a server of your own, or because the save has to live inside an asset such as Easy Save.

  1. Capture the world. This is the step that can refuse, so test the result. It runs on the main thread, on the host only.
  2. Encode it to bytes.
  3. Store the bytes. From here any thread may do it.

Example, copied from SaveSamples.cs. Compiled against the package’s runtime assembly; not run in Unity. myStore stands for your own storage:

var captured = IntrigueSave.State.Capture(); // main thread, host only
if (!captured.Ok) return false;
var encoded = IntrigueSave.Codec.Encode(captured.Data, new EncodeOptions { Title = "Cloud save" });
if (!encoded.Ok) return false;
myStore["intrigues"] = encoded.Bytes; // from here any thread may store the bytes
  1. Decode the bytes. It is checked and never throws.
  2. Stage the data. Nothing changes yet. The report tells you what a load would find in your game.
  3. Restore. Restore works in place. Use RestoreAsync(staged, scene) to load a scene.

Example, copied from SaveSamples.cs. Compiled against the package’s runtime assembly; not run in Unity.

var decoded = IntrigueSave.Codec.Decode(bytes); // checked; never throws
if (!decoded.Ok) return "decode: " + decoded.Reason;
var staged = IntrigueSave.State.Stage(decoded.Data); // nothing in the game changes yet
var restored = IntrigueSave.State.Restore(staged); // in place; across scenes use RestoreAsync
return restored.Ok ? "ok " + staged.Report.Actors : "restore: " + restored.Reason;
Step Signature Source file
Capture static CaptureResult Capture(CaptureOptions options = null) State/IntrigueSave.cs
Encode static EncodeResult Encode(SaveData data, EncodeOptions options = null) State/IntrigueSave.Facade.cs
Decode static DecodeResult Decode(byte[] bytes, DecodeOptions options = null) State/IntrigueSave.Facade.cs
Stage static StagedLoad Stage(SaveData data, RestoreOptions options = null) State/IntrigueSave.cs
Restore static LoadResult Restore(StagedLoad staged) State/IntrigueSave.cs

You will see: every result has Ok and a Reason. Nothing here throws.

Test the flag, and read the reason only when it is false, so that a refused capture or a damaged save tells you what happened in words you can show to a player.

  • Capture refuses: for example on a multiplayer client or while a scheme’s node is running. Capture also needs the Intrigue Manager and the main thread. Read captured.Reason.
  • Your game has secret save parts: these bytes hold them as plain text, because only the slots encrypt them. Use the slots for such a game.
  • A second Restore of the same staged load answers AlreadyRestored. Stage again.
  • The save is binary. Never store it as a plain string. Keep the bytes, or turn them into Base64 text if your store only takes text, and remember that PlayerPrefs suits small saves only.

Everything the steps accept, the options and the statuses: Storing the bytes yourself and Save and load results.