CopySlot

Summary: Copy all saves from one slot to another.

Description

Copy all saves and metadata from one slot to another. The source slot must exist and the destination slot must be new.

Declaration

C#
public static SaveResult CopySlot(string from, string to);

Parameters

ParameterTypeDescription
fromstringName of the slot to copy.
tostringName of a new destination slot.

Returns

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

Example

Create CopyProfileSlot.cs and attach it to an active GameObject. Create a save in profile1 before trying this example. Enter Play mode, open the component’s Inspector menu and choose Copy Profile. The destination slot profile1-copy must be new.

C#
using Gley.SaveSystem;
using UnityEngine;

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

        SaveResult result = API.CopySlot("profile1", "profile1-copy");

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