Cloud save

Store per-player JSON documents under keys, with revisions so two devices never silently overwrite each other.

On this page

Save#

Save any serializable object (Unity) or JSON value under a key. Each save gets the next revision number.

C#
[System.Serializable]
public class Progress { public int level; public int coins; }

var saved = await Majacloud.CloudSave.SaveAsync("progress", new Progress { level = 3, coins = 120 });
if (saved.Ok) Debug.Log("Saved revision " + saved.Value.Revision);

Load#

Loading a key that was never saved returns not_found: treat it as the first launch.

C#
var loaded = await Majacloud.CloudSave.LoadAsync<Progress>("progress");
if (loaded.Ok) progress = loaded.Value.Data;
else if (loaded.IsNotFound) progress = new Progress(); // first launch

Revisions and conflicts#

Pass the revision you loaded as the expected revision. If another device saved in the meantime, the save fails with revision_mismatch and details.current_revision; load again, merge and retry. An expected revision of 0 means create only.

C#
// Only overwrite the revision we loaded; another device may have saved since
var safe = await Majacloud.CloudSave.SaveAsync("progress", progress, expectedRevision: loaded.Value.Revision);
if (!safe.Ok && safe.Error.Code == MajacloudErrorCode.RevisionMismatch)
{
    // Load again, merge, and save with the new revision
}

List and delete#

List the player's keys with their revisions and sizes, and delete keys you no longer need:

C#
var keys = await Majacloud.CloudSave.ListAsync();
foreach (var entry in keys.Value) Debug.Log(entry.Key + " r" + entry.Revision + " " + entry.SizeBytes + " B");

await Majacloud.CloudSave.DeleteAsync("old_slot");

Limits#

  • Up to 256 KB per document and 100 keys per player.
  • Keys may contain letters, numbers, dots, dashes and underscores (up to 80 characters).
  • Total storage per account depends on the plan (see Limits); above it saves fail with plan_limit and nothing is deleted.

Search page titles, headings and text.

↑↓ to navigate ↵ to open Esc to close