DeleteAll

Summary: Delete every save across all slots.

Description

Delete every save across all slots in the active storage.

With File or PlayerPrefs storage, this also attempts to remove originals registered through MapV2 across all slots, even if they have never been loaded. Mapped files can be outside the current save folder.

Declaration

C#
public static SaveResult DeleteAll();

Returns

A SaveResult for the deletion. Check IsSuccess on the result.

Example

Create DeleteAllTestSaves.cs and attach it to an active GameObject. This deletes every save in every slot in the active storage. Use a test project. Enter Play mode, open the component’s Inspector menu and choose Delete All Test Saves.

C#
using Gley.SaveSystem;
using UnityEngine;

public class DeleteAllTestSaves : MonoBehaviour
{
    // Use this Inspector command to test deleting all saves in Play mode.
    // In your game, call the API from your own reset code.
    [ContextMenu("Delete All Test Saves")]
    private void RemoveSaves()
    {
        if (!Application.isPlaying)
        {
            return;
        }

        SaveResult result = API.DeleteAll();

        if (result.IsSuccess)
        {
            Debug.Log("Deleted all saves.", this);
        }
        else
        {
            Debug.LogWarning($"Delete failed ({result.Status}): {result.Message}", this);
        }
    }
}
On This Page