DeleteSlot

Summary: Delete a slot and all its saves.

Description

Delete a slot and all its saves.

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

Declaration

C#
public static SaveResult DeleteSlot(string slot);

Parameters

ParameterTypeDescription
slotstringName of the slot.

Returns

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

Example

Create DeleteTestProfile.cs and attach it to an active GameObject. This deletes the profile1 slot and every save inside it. Use a test project. Enter Play mode, open the component’s Inspector menu and choose Delete Test Profile.

C#
using Gley.SaveSystem;
using UnityEngine;

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

        SaveResult result = API.DeleteSlot("profile1");

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