RecoveredFromBackup

Summary: Runs when a load recovers from a temporary or backup copy.

Description

Runs when a load recovers from a temporary or backup copy. It runs before LoadCompleted. The handler receives the original failure status, while the final load reports Success. The same event covers recovery from a temporary copy. Subscribe on API.Default to observe calls through the static API.

Declaration

C#
public event Action<SaveEventInfo, SaveStatus> RecoveredFromBackup;

Parameters

Handler argumentTypeDescription
infoSaveEventInfoThe name and slot of the recovered save.
originalStatusSaveStatusThe failure status of the main copy before recovery.

Example

Create WatchSaveRecovery.cs. Attach this script and enter Play mode. It writes twice to an independent MemoryStorage, moves the main copy aside, then loads the backup. The Console reports recovery after NotFound.

This test uses its own SaveService and keeps its saves in memory. To observe recovery in your game, subscribe to API.Default.RecoveredFromBackup.

C#
using Gley.SaveSystem;
using UnityEngine;

public class WatchSaveRecovery : MonoBehaviour
{
    private const string SaveName = "event-recovery-example";
    private const string StorageKey = "default/" + SaveName;

    private void Start()
    {
        MemoryStorage storage = new MemoryStorage("event-recovery");
        SaveService service = new SaveService();
        service.SetStorage(storage);

        if (!service.Save(transform.position, SaveName).IsSuccess ||
            !service.Save(transform.position + Vector3.right, SaveName).IsSuccess)
        {
            Debug.LogWarning("Could not prepare the recovery example.", this);
            return;
        }

        storage.Quarantine(StorageKey);
        service.RecoveredFromBackup += OnRecoveredFromBackup;
        service.Load<Vector3>(SaveName);
        service.RecoveredFromBackup -= OnRecoveredFromBackup;
    }

    private void OnRecoveredFromBackup(SaveEventInfo info, SaveStatus originalStatus)
    {
        Debug.Log($"Recovered {info.Slot}/{info.Name} after {originalStatus}.", this);
    }
}
On This Page