Save System
This section covers the save system API for custom runtime integrations.
IAssetReferenceStrategy
IAssetReferenceStrategy lets your project control how PlayMaker captures and restores references to project assets.
Use this when:
- You set Asset References to Custom in
PlayMakerSaveSettings - Your project already has its own asset catalog, key database, or runtime lookup system
- You need more control than the built-in registry workflow provides
Interface:
public interface IAssetReferenceStrategy
{
bool CanReferenceType(Type assetType);
bool TryCapture(UnityEngine.Object asset, ObjectReference reference);
UnityEngine.Object Resolve(ObjectReference reference, Type expectedType);
}
How It Fits In
When PlayMaker saves a variable that points to an asset, it needs a stable key instead of serializing the asset itself.
Your strategy is responsible for:
- Deciding which asset types it supports
- Converting an asset into a stable key during save
- Resolving that key back into the correct asset during load
The saved key is stored in ObjectReference.AssetKey.
Methods
CanReferenceType
Return true for asset types your strategy can save and restore.
Typical examples include:
SpriteAudioClipMaterialScriptableObjectsubclasses
Scene references such as GameObject and Component are handled separately and should not be treated as asset references here.
TryCapture
Called when PlayMaker needs to save an asset reference.
Your implementation should:
- Validate the asset
- Generate or look up a stable identifier
- Write that identifier to
reference.AssetKey - Return
trueif capture succeeded
If the asset cannot be represented safely, return false.
Resolve
Called when PlayMaker loads a saved asset reference.
Your implementation should:
- Read
reference.AssetKey - Look up the asset in your runtime system
- Return an object compatible with
expectedType
Return null if the key cannot be resolved.
Registering The Strategy
Setting Asset References to Custom does not assign a strategy automatically. Your project must assign one in code before save/load begins.
Example:
using System;
using HutongGames.PlayMaker.SaveSystem;
using UnityEngine;
public sealed class MyAssetReferenceBootstrap
{
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)]
private static void Init()
{
ObjectReferenceSerializer.AssetReferenceStrategy = new MyAssetReferenceStrategy();
}
}
public sealed class MyAssetReferenceStrategy : IAssetReferenceStrategy
{
public bool CanReferenceType(Type assetType)
{
return typeof(ScriptableObject).IsAssignableFrom(assetType);
}
public bool TryCapture(UnityEngine.Object asset, ObjectReference reference)
{
if (asset == null || reference == null)
return false;
reference.AssetKey = asset.name;
return true;
}
public UnityEngine.Object Resolve(ObjectReference reference, Type expectedType)
{
if (reference == null || string.IsNullOrEmpty(reference.AssetKey))
return null;
return MyAssetDatabase.LoadByKey(reference.AssetKey, expectedType);
}
}
Replace asset.name with a real stable identifier from your project. In production, asset names are usually not unique enough to use as save keys.
Design Notes
- Use stable keys that survive domain reloads, scene changes, and restarts.
- Avoid editor-only APIs inside
Resolve. - Make sure your resolver works in a player build, not just in the Unity Editor.
- If your game loads content asynchronously, resolve through your own synchronous lookup layer or preload the data before
LoadGame.