MapV2

Summary: Map a save name to a version 2 file path or PlayerPrefs key.

Description

Map a save name to a version 2 file path or PlayerPrefs key. When using file storage, pass the absolute path to the version 2 file. When using PlayerPrefs, pass the original key.

Registering the mapping leaves the original in place. If the new named save is missing, Load can read the original. After Save System reads the mapped data, the next successful write to the same name and slot attempts to remove the original. A write before the original is read leaves it in place.

Delete, DeleteSlot, and DeleteAll attempt to remove matching mapped originals even if they have never been loaded. For file storage, this can remove a mapped file outside the current save folder.

Declaration

C#
public static void MapV2(string name, string v2Path, string slot = null);

Parameters

ParameterTypeDescription
namestringName of the save.
v2PathstringAbsolute path for file storage or the original key for PlayerPrefs.
slotstringOptional. Slot to link in. Null uses the default slot.

Exceptions

ExceptionThrown when
ArgumentNullExceptionname is null.
ArgumentExceptionv2Path is empty, the save or slot name is invalid, or, with file storage, the path is not absolute or is the same as the new save’s path.
InvalidOperationExceptionThe method is called from a thread other than Unity’s main thread.

Example

Create MapLegacySave.cs and attach it to an active GameObject. For file storage, enter the absolute path to an existing v2 save in the Inspector. For PlayerPrefs, enter the original key. Enter Play mode to register the mapping. A later load can use the name legacy-progress.

C#
using Gley.SaveSystem;
using UnityEngine;

public class MapLegacySave : MonoBehaviour
{
    [SerializeField] private string _legacyLocation = "";

    private void Awake()
    {
        if (string.IsNullOrWhiteSpace(_legacyLocation))
        {
            Debug.LogWarning("Enter the original save path or key.", this);
            return;
        }

        API.MapV2("legacy-progress", _legacyLocation);
        Debug.Log("Mapped the v2 save to legacy-progress.", this);
    }
}
On This Page