Skip to content

Game.Assets.SaveGameMetadata

Assembly:
Namespace: Game.Assets

Type: class

Base: Metadata

Summary:
SaveGameMetadata is a metadata wrapper for SaveInfo assets. It resolves metadata information (display name, path, owner, timestamps, cloud target, readonly state) from the underlying SourceMeta and links the corresponding SaveGameData asset to the SaveInfo target. It also exposes convenience helpers such as the persistent storage path and a validity check that verifies the presence and validity of the linked save game data.


Fields

  • public const string kExtension = ".SaveGameMetadata"
    This constant defines the file extension used for save game metadata assets.

  • public static readonly Func<string> kPersistentLocation = () => "Saves/" + PlatformManager.instance.userSpecificPath
    A delegate that returns the persistent folder location used for saves for the current platform/user. Use this to build persistent paths or locate the save folder in platform-specific contexts.

Properties

  • public bool isValidSaveGame { get; }
    Determines whether the metadata refers to a valid save game. It returns true only when:
  • The base Metadata state is valid (base.isValid),
  • The target.saveGameData is non-null,
  • The save is not readonly, and
  • The underlying saveGameData reports itself as valid. This is a quick check to confirm you can open/operate on the save.

  • public override IEnumerable<string> modTags { get; }
    Extends the base metadata mod tags sequence by appending the "Savegame" tag. Iterate this property to get tags used to categorize the asset.

Constructors

  • public SaveGameMetadata()
    No explicit constructor is defined in the source; the default parameterless constructor is provided by the compiler. Instances are typically created/managed by the asset metadata system (Asset/Metadata database), not manually constructed in most modding scenarios.

Methods

  • protected override void OnPostLoad() : System.Void
    Called after the metadata has finished loading. Behavior:
  • Returns early unless the metadata state is LoadState.Full.
  • Verifies the database actually contains this id.
  • Sets base.target.id to the identifier.
  • Obtains the SourceMeta for the asset and links this metadata instance to base.target.metaData.
  • If the asset is packaged and the package asset exists, uses the package's displayName for the target; otherwise uses the meta.displayName.
  • Populates target.path, target.isReadonly (inverted belongsToCurrentUser), target.lastModified (converted to local time), and target.cloudTarget.
  • If target.saveGameData is null, attempts to find and attach the related SaveGameData asset by:
    • Looking up an asset whose hash matches the save data GUID derived from the meta.path (falling back to extension index 1), or
    • If packaged, finding a SaveGameData by matching package id. This ensures the SaveInfo target is fully populated and linked to the appropriate SaveGameData after metadata load.

Usage Example

// Example: using a loaded SaveGameMetadata instance (obtained from the asset/metadata database)
void InspectSave(SaveGameMetadata saveMeta)
{
    if (saveMeta == null)
        return;

    // Check if the metadata represents a usable save game
    if (saveMeta.isValidSaveGame)
    {
        var saveInfo = saveMeta.target;
        var saveData = saveInfo.saveGameData;

        UnityEngine.Debug.Log($"Save name: {saveInfo.displayName}");
        UnityEngine.Debug.Log($"Path: {saveInfo.path}");
        UnityEngine.Debug.Log($"Last modified: {saveInfo.lastModified}");
        UnityEngine.Debug.Log($"Cloud target: {saveInfo.cloudTarget}");
        UnityEngine.Debug.Log($"Is readonly: {saveInfo.isReadonly}");

        // Work with saveData as needed...
    }
    else
    {
        UnityEngine.Debug.Log("Save metadata is not a valid save game.");
    }
}

// Example: get the platform-specific persistent saves folder
string savesFolder = SaveGameMetadata.kPersistentLocation();
UnityEngine.Debug.Log("Saves folder: " + savesFolder);