CodeBlanks Logo Icon CodeBlanks

Save game schema

Learn save schema design and versioning.

Save Data Model and Version Tracking

As games evolve, new fields are added to the save data model or old fields are removed. To ensure older save files remain intact across updates, a saveVersion number should always be included in the model.

[System.Serializable]
public class GameSaveData {
    public int saveVersion = 2; // Version tracking number
    public int playerLevel;
    public float playTime;
}

This field immediately identifies which game release generated the save file when opened.

Data Migration Strategy

When the file's saveVersion is lower than the current build, migration logic runs. Newly added fields are populated with defaults, keeping the player's past accomplishments intact.

if (data.saveVersion < 2) {
    // Upgrade from version 1 to 2:
    // Initialize new features with defaults
    data.saveVersion = 2;
}

This ensures players never have to wipe their progression when downloading a new patch.

Practice Version check and data model

Define a Start method. Inside, declare int saveVersion = 2; and print "Kayit veri surumu: " + saveVersion to the console.

Starter code

Player.cs
using UnityEngine;

public class VersionManager : MonoBehaviour
{
    // Start icinde saveVersion tanimla ve yazdir
}

Sample solution

Player.cs
using UnityEngine;

public class VersionManager : MonoBehaviour
{
    void Start()
    {
        int saveVersion = 2;
        Debug.Log("Kayit veri surumu: " + saveVersion);
    }
}

Expected output

Kayit veri surumu: 2

Questions and answers

Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.

1 Which information should be retained in the save object to maintain backward compatibility and prevent corrupt saves across updates?

  • Version number Correct answer
  • Monitor refresh rate (Hz)
  • GPU core temperature
  • Serial number of the hard drive where game is installed

Explanation: A version number stored inside save data allows safe detection and migration of data from earlier game versions.

2 Version check

Question
if (saveData.____ < 2) { MigrateToVersion2(saveData); }
Answer
if (saveData.saveVersion < 2) { MigrateToVersion2(saveData); }

Explanation: The 'saveVersion' field is checked to inspect the version of the save object.

3 Versioning concepts

Term Meaning
saveVersion Version number of the save file
Migration Upgrading old saves to the new format
Backward Compatibility Backward compatibility support
Default Value Default assigned to newly added fields

All lessons in Advanced