Delete

Summary: Delete a named save from a slot.

Description

Delete a named save from a slot.

With File or PlayerPrefs storage, this also attempts to remove the original v2 file or key registered for this save name and slot through MapV2, even if it has never been loaded. A mapped file can be outside the current save folder.

Declaration

C#
public static SaveResult Delete(string name, string slot = null);

Parameters

ParameterTypeDescription
namestringName of the save.
slotstringOptional. Slot to delete from. Null uses the default slot.

Returns

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

Example

Create DeleteSavedPosition.cs and attach it to an active GameObject. This deletes the synchronous example save from the default slot. Use a test project. Enter Play mode, open the component’s Inspector menu and choose Delete Example Save.

C#
using Gley.SaveSystem;
using UnityEngine;

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

        SaveResult result = API.Delete("position-sync-example");

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