Save slots

Summary: Build Continue and New game actions, keep separate profiles, show slot metadata, and copy or delete slots.

A slot groups named saves for one profile or playthrough. For example, progress in slot-1 and progress in slot-2 are separate saves. This guide builds a small menu that keeps the selected profile’s data together.

Complete the Setup Guide first. These examples use synchronous calls to keep the menu flow clear. Call Save System from Unity’s main thread, such as a UI button handler.

1. Define the data for a new game

Create GuideProgressData.cs. Its constructor provides the initial values for a new game. Your game is responsible for updating these properties as the player progresses, including tracking playtime.

C#
using System;
using UnityEngine;
 
namespace MyGame
{
    [Serializable]
    public class GuideProgressData
    {
        [SerializeField] private int _coins;
        [SerializeField] private int _level;
        [SerializeField] private float _playtimeSeconds;
 
        public int Coins { get => _coins; set => _coins = value; }
        public int Level { get => _level; set => _level = value; }
        public float PlaytimeSeconds { get => _playtimeSeconds; set => _playtimeSeconds = value; }
 
        public GuideProgressData()
        {
            _coins = 0;
            _level = 1;
            _playtimeSeconds = 0f;
        }
    }
}

2. Connect Continue, New game and Save

Create ProfileSaveMenu.cs and attach it to a GameObject in your menu scene. Connect your buttons to its public methods. In your UI script, read Status to update the status label, use CanSave to enable or disable Save, and call HasSavedGame() to enable or disable Continue. Refresh these when the menu opens and after selecting a profile or completing an action. Apply Data to your gameplay components after a successful load or new game.

C#
using UnityEngine;
using Gley.SaveSystem;
 
namespace MyGame
{
    public class ProfileSaveMenu : MonoBehaviour
    {
        private const string ProgressName = "progress";
        private string _selectedSlot = "slot-1";
 
        public GuideProgressData Data { get; private set; } = new GuideProgressData();
        public string Status { get; private set; } = "";
        public bool CanSave { get; private set; }
 
        public bool HasSavedGame()
        {
            return API.Exists(ProgressName, _selectedSlot);
        }
 
        public void SelectProfile(string slot)
        {
            if (slot != "slot-1" && slot != "slot-2" && slot != "slot-3")
            {
                Status = "Choose Slot 1, Slot 2 or Slot 3.";
                return;
            }
 
            _selectedSlot = slot;
            CanSave = false;
            Status = "Choose Continue or New game.";
        }
 
        public void ContinueGame()
        {
            CanSave = false;
            var options = new SaveOptions { Slot = _selectedSlot };
            LoadResult<GuideProgressData> result = API.Load<GuideProgressData>(ProgressName, options);
 
            if (result.IsSuccess)
            {
                Data = result.Data;
                CanSave = true;
                Status = "Progress loaded.";
                if (result.RecoveredFromBackup)
                {
                    Status = "A recovered save was loaded. Some recent progress may be missing.";
                }
                return;
            }
 
            if (result.Status == SaveStatus.NotFound)
            {
                Status = "No saved game in this profile.";
                return;
            }
 
            Status = "Could not load this profile: " + result.Status;
        }
 
        public void NewGameConfirmed()
        {
            CanSave = false;
            SaveResult result = API.DeleteSlot(_selectedSlot);
            if (!result.IsSuccess)
            {
                Status = "Could not clear this profile: " + result.Status;
                return;
            }
 
            Data = new GuideProgressData();
            CanSave = true;
            Status = "New game started.";
        }
 
        public void SaveGame()
        {
            if (!CanSave)
            {
                Status = "Load a profile or start a new game before saving.";
                return;
            }
 
            var options = new SaveOptions { Slot = _selectedSlot };
            SaveResult result = API.Save(Data, ProgressName, options);
            if (!result.IsSuccess)
            {
                Status = "Could not save: " + result.Status;
                return;
            }
 
            Status = "Progress saved.";
        }
    }
}

Ask the player to confirm before calling NewGameConfirmed. It deletes all saves and retained .broken files in this profile. The new data stays in memory until SaveGame runs. If you want New game to create a save immediately, call SaveGame after initializing the data and check the result.

Exists only checks for a stored save, including a possible recovery copy. It does not prove that the save can be loaded. Continue must still inspect the load result. Use Handling load results to choose the message and recovery action for each failure.

3. Add more profiles

Connect the profile buttons to SelectProfile with slot-1, slot-2 or slot-3. The component uses that selected slot for saving, loading, checking and deleting. Changing a selection disables saving until Continue succeeds or a confirmed New game starts. This prevents one profile’s in-memory data from being written into another by accident.

Use SaveOptions.Slot for save and load calls. Methods such as Exists and Delete take the slot as a separate argument. Keep the save name plain: use progress, not slot-1/progress.

Without a slot, calls use default. You can keep shared settings or a last-used-slot name there. Always pass the profile slot when writing profile data.

Save and slot names allow only A–Z, a–z, 0–9, hyphens and underscores, up to 64 characters, and are normalized to lowercase. Accented letters and other Unicode characters are rejected. Paths, names starting with a dot and Windows reserved names such as con are rejected. Put player-facing names such as “Alex’s Adventure” in metadata.

4. Save menu details as metadata

After saving the progress successfully, write the level and playtime used by the slot list. Save System updates the slot’s last-saved UTC time automatically. The dictionary below belongs to the metadata API; it is not a dictionary field inside your JsonUtility save class.

C#
using System.Collections.Generic;
using System.Globalization;
using Gley.SaveSystem;
 
namespace MyGame
{
    internal class SlotMetadataWriter
    {
        private const float SecondsPerMinute = 60f;
 
        public SaveResult Write(string slot, GuideProgressData data)
        {
            int minutes = (int)(data.PlaytimeSeconds / SecondsPerMinute);
            var details = new Dictionary<string, string>
            {
                { "level", data.Level.ToString(CultureInfo.InvariantCulture) },
                { "playtime", minutes.ToString(CultureInfo.InvariantCulture) + " min" }
            };
 
            return API.SetSlotMetadata(slot, details);
        }
    }
}

For example, inside SaveGame, call new SlotMetadataWriter().Write(_selectedSlot, Data) after the progress save succeeds and inspect its SaveResult too. A failed metadata write does not undo the progress save; report that the menu details could not be updated. Use the same data snapshot for the save and metadata.

5. Build the slot list

ListSlots reads slot metadata without deserializing each progress save. Call it when opening or refreshing the menu, rather than every frame. The returned list includes existing slots only; add your own Empty entries for unused fixed slots.

C#
using System;
using System.Collections.Generic;
using Gley.SaveSystem;
 
namespace MyGame
{
    internal class ProfileSlotList
    {
        public IReadOnlyList<SlotInfo> GetProfiles()
        {
            IReadOnlyList<SlotInfo> slots = API.ListSlots();
            var profiles = new List<SlotInfo>();
 
            foreach (SlotInfo slot in slots)
            {
                foreach (string key in slot.Keys)
                {
                    if (key == "progress")
                    {
                        profiles.Add(slot);
                        break;
                    }
                }
            }
 
            return profiles;
        }
 
        public string GetLabel(SlotInfo slot)
        {
            if (!slot.Custom.TryGetValue("level", out string level))
            {
                level = "?";
            }
 
            if (!slot.Custom.TryGetValue("playtime", out string playtime))
            {
                playtime = "Unknown playtime";
            }
 
            string savedAt = "Unknown save time";
            if (slot.LastSavedUtc != DateTime.MinValue)
            {
                savedAt = slot.LastSavedUtc.ToLocalTime().ToString("g");
            }
 
            return slot.Name + " | Level " + level + " | " + playtime + " | " + savedAt;
        }
    }
}

Filtering by Keys avoids showing a shared settings slot as a game profile. Metadata can be missing or one save behind after a crash, so show fallback labels and load the progress itself to get authoritative gameplay values. If listing storage fails, ListSlots returns an empty list and logs a warning; an empty list alone is not proof that the player has no saves.

6. Copy or delete a profile

ActionCallWhat to check
Copy Slot 1 to Slot 2API.CopySlot("slot-1", "slot-2")Check IsSuccess. A target that already holds saves is refused with InvalidName; a missing source returns NotFound.
Delete one named saveAPI.Delete("progress", "slot-1")Removes its main, temporary and backup copies. Keeps .broken copies for support.
Reset the whole profileAPI.DeleteSlot("slot-1")Removes every Save System save in the slot, including .broken copies. Ask the player to confirm first.

These calls return SaveResult. For an occupied copy target, offer another slot or an explicit overwrite confirmation before deleting that target. Copy preserves the stored data and metadata; it does not load the data or upgrade its version. It is not an all-or-nothing operation if the app is terminated mid-copy.

Refresh the slot list after a successful operation. Deleting stored saves does not reset scene objects or clear your in-memory Data; update those separately. Avoid DeleteAll for a single-profile reset, because it affects every slot.

Try the complete sample

The Save Example includes three selectable slots, metadata labels, remembering the last-used slot, and separate data, gameplay and UI scripts.

On This Page