Başar BallıözProduct Engineer
← All posts

Cloud save in Godot 4: Play Games, iCloud and one conflict rule

When a family changes phones, the pet has to come along. Tibblo syncs its save through Google Play Games on Android and iCloud on iPhone. The platform parts were the easy half. Deciding which save wins, and never deciding it silently, was the real design work.

By Başar Ballıöz · · 4 min read

The short answer

For cloud save in a Godot 4 mobile game: put every platform behind one small interface (load, save, available), store the whole save as one JSON snapshot with a revision number, keep a local record of the last revision and file hash you synced, and use a tiny decision table to choose upload, download, nothing or conflict. On a conflict, show both saves and let the player choose.

Below is how Tibblo does it.

For parents, the same feature is explained step by step in switching phones without losing your child's game progress.

1. One interface, four backends

The game talks to a single cloud service script. Calls are asynchronous and answers come back as signals, because both platforms answer later. Behind it sit four implementations:

  • Google Play Games saved games on Android, through the open-source GodotPlayGameServices plugin;
  • iCloud key-value storage on iPhone and iPad, through Tibblo's own small GDExtension;
  • a null cloud for desktop, which is simply unavailable and says so in Settings;
  • a fake cloud in memory for tests, which answers on the next frame like a real backend, can be switched offline, and counts uploads so a test can prove one happened exactly once.

The plugin scripts are loaded by path, never by class name, so desktop builds and tests run without the Android plugin installed.

2. The whole save as one snapshot

On both platforms the cloud holds exactly one item, named tibblo-save, containing JSON in the same format: the save itself, a revision number, the device id that wrote it, the time it was written and a short summary for humans. One format means one decoder, and a save written by an Android phone could be read by the same code on iOS.

Size is not a problem: a save is about 10 KB, and iCloud key-value storage allows 1 MB per app.

3. The decision table

Each device keeps its own sync record, which is never synced itself: the cloud revision it last matched, and the MD5 hash of the save file at that moment. Comparing the current file hash with the stored one tells the game whether anything changed locally, without comparing whole saves.

From there the rule fits in a few lines:

SituationDecision
New install, no pet yet, cloud has a saveDownload
Local save changed and the cloud is newer than the last matchConflict
Only the cloud is newerDownload
Only the local save changedUpload with the next revision
Nothing changedNothing

The function is pure, so the tests drive every row of the table directly.

4. Conflicts are never resolved silently

"Last write wins" is the easy answer and the wrong one for a children's game. If a child played on a tablet while a parent's phone was offline, either save may be the one that matters to them.

So a conflict opens a sheet with both saves side by side, in words: the pets' names, the best level, the coins and when each was last played, with the date written in numbers so it reads the same in every language. The player picks one, then confirms, because the other side's progress will be replaced.

5. Off by default, no surprise sign-ins

Cloud save is the player's choice, and it is off on a new install. Nothing signs a child in to Play Games or iCloud on its own:

  • On Android, Play Games only starts when the game first needs the cloud, which only happens with Cloud save turned on. If nobody is signed in, it asks once.
  • On iPhone there is no sign-in screen at all: the device's own iCloud account is used. Without one, Settings says cloud save is unavailable.

iCloud also delivers another iPhone's save in the background. The game does not swap the pet mid-play; it reads the new snapshot on its next load, at start or when it resumes.

Common questions

Does Godot 4 have built-in cloud save?

No. You use a platform plugin, such as a Play Games Services plugin on Android, and a native extension or plugin for iCloud on iOS.

Should I use iCloud key-value storage or CloudKit for game saves?

For a small save, key-value storage is enough and much simpler. It is limited to 1 MB per app, so larger saves need CloudKit or files in iCloud Drive.

How do I detect that a save changed since the last sync?

Store a hash of the save file when it last matched the cloud, and compare it with the file's current hash.

What I learned

Sync is a decision problem first. The platform APIs were a few hundred lines. The table that decides upload, download or conflict is what makes it trustworthy.

Ask a human when two histories disagree. A clear side-by-side choice costs one screen and saves a lost pet.

Build a fake backend first. Every rule here was tested against the in-memory cloud long before a real phone was involved.

More posts

LLM API cost control per user: how RPMBase keeps the AI bill boundedHow RPMBase keeps OpenAI costs bounded per user: server-side limits, a worst-case cost reservation, atomic budgets in MongoDB, shared pools for free accounts and a hard cap. Keyword cannibalization in practice: one query, three moves, zero impressionsA real case from RPMVault: moving "motorcycle maintenance app" between pages three times cost its impressions. The query ownership rules, title limits and lock test I use now.