Developing Mobile Game Save System
Loss of progress is the worst thing that can happen to a player. Passed 30 levels, bought boosters, unlocked characters — and after reinstall or device switch nothing's there. Rating in app store drops, user leaves. Save system is a critical component that can't be added "later".
What and Where to Store
Game progress consists of several data types with different requirements:
Critical data (level, currency, purchases) — must sync with server and never be lost. Stored locally + cloud.
Game progress (passed levels, achievements, unlocked items) — locally + optional sync.
User settings (volume, controls, graphics) — local only, loss is non-critical.
Session data (current level, position, temporary buffs) — memory only, no need to persist between sessions.
Local Storage
For simple games — JSON file or SharedPreferences/UserDefaults. For complex progress with multiple entities — SQLite via Room.
@Entity(tableName = "save_data")
data class SaveDataEntity(
@PrimaryKey val playerId: String,
val level: Int,
val experience: Long,
val coins: Long,
val gems: Int,
val unlockedLevels: String, // JSON array
val inventory: String, // JSON array
val achievements: String, // JSON array
val settings: String, // JSON object
val lastSavedAt: Long,
val version: Int = 1 // for format migrations
)
For Unity — PlayerPrefs for simple values, Application.persistentDataPath + binary file for complex structures. BinaryFormatter is deprecated in Unity 2022 — use JsonUtility or Newtonsoft.Json + File.WriteAllBytes.
// Unity: save via JsonUtility
[Serializable]
public class SaveData {
public int level;
public long coins;
public List<string> unlockedItems = new List<string>();
public int[] levelStars; // 3 stars per level
public long savedAt;
}
public class SaveSystem : MonoBehaviour {
private const string SAVE_FILE = "save.json";
public static void Save(SaveData data) {
data.savedAt = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
string json = JsonUtility.ToJson(data);
string path = Path.Combine(Application.persistentDataPath, SAVE_FILE);
// First write to temp, then rename — atomic operation
string tempPath = path + ".tmp";
File.WriteAllText(tempPath, json);
File.Move(tempPath, path, overwrite: true);
}
}
Write via temp file with subsequent rename — protection from corrupted file if crash during write.
Cloud Synchronization
For cross-platform games — own backend. For iOS-only — Game Center + iCloud. For Android — Google Play Games Services. For Unity — wrappers over both.
// Android: Google Play Games Services
GamesSignInClient.signIn().addOnCompleteListener { task ->
if (task.isSuccessful) {
PlayGames.getSnapshotsClient(activity)
.open(SNAPSHOT_NAME, true, SnapshotsClient.RESOLUTION_POLICY_MOST_RECENTLY_MODIFIED)
.addOnSuccessListener { dataOrConflict ->
if (dataOrConflict.isConflict) {
resolveConflict(dataOrConflict.conflict)
} else {
loadFromSnapshot(dataOrConflict.data)
}
}
}
}
Google Play Games Snapshots API automatically manages conflicts with RESOLUTION_POLICY_MOST_RECENTLY_MODIFIED — newer save wins. For most games this is sufficient.
Save Format Versioning
Data format changes with game updates. Need migration system:
class SaveMigrator {
fun migrate(data: SaveDataEntity): SaveDataEntity {
var current = data
while (current.version < CURRENT_VERSION) {
current = when (current.version) {
1 -> migrateV1toV2(current)
2 -> migrateV2toV3(current)
else -> throw IllegalStateException("Unknown version: ${current.version}")
}
}
return current
}
private fun migrateV1toV2(data: SaveDataEntity): SaveDataEntity {
// Version 2 added daily challenges progress
return data.copy(
dailyChallenges = "{}",
version = 2
)
}
}
Check version on load — if old, migrate to current and save again.
Anti-Cheat Protection
For games with monetization — hash for file modification detection:
fun computeChecksum(data: SaveDataEntity): String {
val content = "${data.playerId}|${data.coins}|${data.gems}|${data.level}|${SECRET_SALT}"
return MessageDigest.getInstance("SHA-256")
.digest(content.toByteArray())
.fold("") { str, byte -> str + "%02x".format(byte) }
}
Server-side validation is more reliable. Critical operations (gem purchase) go through server, client can't just write needed value to file.
Save system with local storage, cloud sync, and format migration for Unity/Android/iOS: 2–3 weeks. Cost calculated individually.







