SetSlotMetadata

Summary: Store one or more named text values on a slot.

Description

Store one or more named text values on a slot.

Declaration

C#
public static SaveResult SetSlotMetadata(string slot, string name, string value);

public static SaveResult SetSlotMetadata(string slot, IDictionary<string, string> values);

Parameters

ParameterTypeDescription
slotstringName of the slot.
namestringSingle-value overload only. Name of the metadata value.
valuestringSingle-value overload only. The text to store.
valuesIDictionary<string, string>Dictionary overload only. The names and texts to store.

Returns

Both overloads return a SaveResult for the metadata update. Check IsSuccess on the result.

Example

Create either SetProfileName.cs or SetProfileDetails.cs using the matching block. Attach the script to an active GameObject. Use a test slot named profile1. In Play mode, the first script sets the player name. The second writes the player name and chapter in one call.

One value · C#
using Gley.SaveSystem;
using UnityEngine;

public class SetProfileName : MonoBehaviour
{
    private void Start()
    {
        SaveResult result = API.SetSlotMetadata("profile1", "playerName", "Alex");

        if (result.IsSuccess)
        {
            Debug.Log("Updated the slot metadata.", this);
        }
        else
        {
            Debug.LogWarning($"Metadata update failed ({result.Status}): {result.Message}", this);
        }
    }
}
Multiple values · C#
using System.Collections.Generic;
using Gley.SaveSystem;
using UnityEngine;

public class SetProfileDetails : MonoBehaviour
{
    private void Start()
    {
        Dictionary<string, string> values = new Dictionary<string, string>
        {
            { "playerName", "Alex" },
            { "chapter", "1" }
        };
        SaveResult result = API.SetSlotMetadata("profile1", values);

        if (result.IsSuccess)
        {
            Debug.Log("Updated the slot metadata.", this);
        }
        else
        {
            Debug.LogWarning($"Metadata update failed ({result.Status}): {result.Message}", this);
        }
    }
}
On This Page