<aside> <img src="/icons/reorder_gray.svg" alt="/icons/reorder_gray.svg" width="40px" />

Navigation

</aside>

🏠 Home Page

Getting Started

Architecture

Level System

Characters & Vehicles

Run Mechanics

World Objects

Boosters & Modifiers

Progression & Economy

UI

Save & Debugging

Modules

Publishing

Reference

💰 Monetization (Ads & IAP)

<aside> 💡 The game uses the SaveController from Watermelon Core. Game code stores data in classes that implement ISaveObject and gets them by type or by key.

</aside>

Subsystems

SaveInitModule

The module is the first one in Project Init Settings. Its fields:

Field Description
Auto Save Delay Seconds between automatic saves. 0 disables the auto-save.
WebGL Prefix Prefix of the localStorage keys in a WebGL build. Set a unique value for every game.
Named Files Extra save files that are downloaded from the cloud at start. Empty when only the default file is used.

SaveController API

Method Description
GetSaveObject<T>() Returns the save object of the type from the default file. The key is resolved from the type.
GetSaveObject<T>(key) Returns the object under an explicit key.
GetSaveObject<T>(fileName, key) Returns the object from a named file.
MarkAsSaveIsRequired() Marks the loaded files as changed.
Save(forceSave, useThreads) Writes the changed files to disk.
DeleteSaveFile() Deletes the default file from disk and cloud.
SyncToCloud() Uploads the local files that wait for the cloud sync.
OnSaveLoaded Event. The save system finished loading.

Change the data in the save object and call SaveController.MarkAsSaveIsRequired(). The next auto-save or Save() writes the file.

How to add save data

  1. Create the class. Implement ISaveObject and mark it with [Serializable]. Add [SaveKey] so the key survives a class rename.

    using System;
    
    namespace Watermelon
    {
        [Serializable]
        [SaveKey("daily_bonus")]
        public class DailyBonusSave : ISaveObject
        {
            public int Streak;
            public long LastClaimTicks;
    
            public void OnBeforeSave()
            {
                // Copy runtime state into the serialized fields here
            }
        }
    }
    
  2. Read it.

    DailyBonusSave save = SaveController.GetSaveObject<DailyBonusSave>();
    
  3. Change it.

save.Streak++;

SaveController.MarkAsSaveIsRequired();

Without [SaveKey], the key is the full name of the class. Renaming the class or the namespace then silently deletes the save. Never change the key after release.

Data saved by this game

Key Class Owner Content
selected_level_id SimpleStringSave LevelSelectionController The level that is loaded on the next start.
max_reached_level_index SimpleIntSave LevelSelectionController The highest reached level.
upgrades:{UpgradeId} UpgradeSavableObject UpgradesController The level of an upgrade.
pickups_{levelId} PickupsSave Pickup Permanent pickups collected in a level.
record_distance_{levelId} SimpleFloatSave RecordWall The record distance of a level.
currency:{type index} Currency.Save CurrencyController The balance of each currency.
Advertisement state AdSave AdsManager For example, the time until forced ads are disabled.

The keys that include an id are namespaced by the Level id or the upgrade id, so two levels never share them.

What is not saved

Editor actions

Menu Description
Edit → Clear Save or Actions → Remove Save Deletes the save file and the PlayerPrefs. Available in edit mode only.
Window → Watermelon → Tools → Save Presets Stores and loads prepared saves. See ‣.
Help → Open Persistent Folder Opens the folder with the save files.

Save on exit from Play Mode

EditorPlayModeSaveGuard force-saves when Play Mode starts to exit, while all scene objects are still alive. SaveController also saves on destroy, but Unity does not order the destroy calls of different objects.

Scene and level data

GameController saves the game before it unloads the scene. A level completion saves before the next level loads. See Run Flow.