Persisting ScriptableObjects with Remember Components
Example: Anatomy of RememberGC2GlobalNameVariablesList
RememberGC2GlobalNameVariablesList Other Examples: RememberPlaymakerGlobalVariable, RememberACGlobalVariables, RememberCozyWeather3, RememberGC2StateMachineVariables, RememberGC2GlobalListVariables etc. from the optional Crystal Save Modules (Adventure Creator, Game Creator 2, Playmaker, Statemachine for GC2, Cozy Weather 3)
Capture data from the mirror
protected override byte[] SerializeComponentData()
{
if (!TryCaptureCurrentState(out var currentSnapshot, logWarnings: true))
{
// When capture fails, clear the cache (if any) and abort the save.
if (!skipSavingWhenUnchanged)
{
hasCachedSnapshot = false;
cachedSnapshot = null;
}
return null;
}
if (skipSavingWhenUnchanged && hasCachedSnapshot && cachedSnapshot != null)
{
if (AreSnapshotsEqual(cachedSnapshot, currentSnapshot))
{
return null;
}
}
var wrapper = CreateWrapperFromSnapshot(currentSnapshot);
byte[] serializedData = SaveDataSerializer.Instance.Serialize(wrapper);
// Refresh the cache so subsequent saves can skip unchanged data.
if (skipSavingWhenUnchanged)
{
cachedSnapshot = DeepCloneSnapshot(currentSnapshot);
hasCachedSnapshot = cachedSnapshot != null;
}
else
{
cachedSnapshot = null;
hasCachedSnapshot = false;
}
return serializedData;
}Serialize using the mirror's data contract
Push data back into the ScriptableObject on load
Template: Remember<YourMirror>
Remember<YourMirror>Troubleshooting mirror-to-asset synchronization
Last updated