Save Example

Summary: Run the complete sample and adapt its data, gameplay and save-manager structure to your own game.

The Save Example combines three save slots, inventory item IDs, a movable object, an async save, and an upgrade from older data. Use it to see how the save data, scene components and UI fit together. For the smallest first save, start with Quick Start.

1. Open the sample

  1. Open Assets/Gley/SaveSystem/Samples/SaveExample/Scenes/SaveExample.unity.
  2. Open Tools › Gley › Save System and create settings if needed. See the Setup Guide for settings and platform options.
  3. Press Play. Change the player values, collect inventory items and move the token with its arrow buttons. Scroll the panel to reach the lower controls.
  4. Select a slot and press Save. Change the values again, then press Load. The scene returns to the saved state.
  5. Stop and restart Play mode. The example tries to remember and load the slot used by the last successful save or load. Selecting a slot alone does not remember or load it.

If you run the sample without settings, it still works, saving unprotected and logging a warning. Restart Play mode after changing settings so the sample reads the new values.

2. Try the workflows

Control or actionWhat to observe
Choose Slot 1, Slot 2 or Slot 3Each slot stores its own player save. Select a slot, then explicitly Save or Load.
Save while editing valuesSlot and save-operation buttons are disabled while saving. You can keep changing values while saving. Only the values captured when you pressed Save are stored; press Save again to store later changes.
Reset ValuesResets the scene to new-game values. It does not delete or overwrite the stored save.
Delete SlotDeletes the selected slot’s saves. It leaves the values currently shown in the scene unchanged.
Load Older Version SaveLoads embedded version-1 data into the scene through LoadFromString. It does not write it to a slot. The upgrade copies music volume into the SFX setting added in version 2.
Show logShows whether each operation succeeded or failed, including updates to slot details and the last-used slot. Also shows backup recovery information when available.

3. Read the scripts

The scripts are in the sample’s Scripts folder.

ScriptWhat to reuse
PlayerDataThe versioned data class. Private serialized fields hold values; public properties expose them. The constructor initializes a fresh game, including the inventory list. OnUpgrade handles older saved data.
InventoryItemAn inventory entry containing an item ID and count.
PlayerProfile and MovableObjectScene components with WriteTo(PlayerData) and ReadFrom(PlayerData) methods that collect and apply values.
GameSaveManagerCollects values from the scene, saves them to the selected slot, and applies loaded values back to the scene. Start here to see how the sample uses the Save System API.
SaveExampleUIConnects buttons and labels to the manager and scene components. It does not call the Save System API directly.
OlderVersionSaveThe embedded older save used by the upgrade button.

4. Adapt the structure to your game

  1. Use PlayerData as a starting point for your own serializable data class. Set default values for a new game and initialize any lists. Store values and object IDs, rather than GameObject or asset references.
  2. Follow PlayerProfile and MovableObject: use WriteTo to copy values from your components into the data class, and ReadFrom to apply loaded values.
  3. Adapt GameSaveManager to collect and restore your game’s data. Choose your own save and slot names. When collecting inventory data, copy the entries so changes during saving cannot affect the data being saved.
  4. Connect your UI to the manager’s save and load methods. Use IsBusy to disable conflicting actions while saving.
  5. Save, restart Play mode, and load again to check that your values are restored. Repeat this test in a build.

The sample uses new-game defaults when a load fails. Before using this behaviour in your game, read Handling load results to avoid replacing existing progress after a failed load.

5. Pause and quit behaviour

Save On Pause And Quit is disabled on GameSaveManager in the sample scene. This prevents stopping Play mode from overwriting your saved values.

Enable it to save the current values when the application pauses or quits. The manager uses synchronous API.Save for these saves.

These save triggers are defined in GameSaveManager. In your own game, choose when to call save and test that behaviour on each target platform.

Related guides

On This Page