1. Mark the variable you want to remember
Add [StorageSync("your_key")] above a field in your script. The key is the name used to find its saved value.
using CSS;
using UnityEngine;
public sealed class SyncedPlayer : MonoBehaviour
{
[StorageSync("player.coins")]
public int coins;
[StorageSync("player.health")]
[SerializeField] private int health = 100;
public void CollectCoin() => coins++;
public int Health => health;
}
2. Change the value as usual
Call CollectCoin(), or change coins in your own code. The plugin picks up the change during its next update and stores it in save memory.
When another instance uses the same key, it picks up that value. If there is no value yet, the field keeps its starting value.
Call await SaveSystem.SaveAsync(), or use your normal checkpoint/automatic saves, to keep the data after the game closes. Fields are checked again before saving.
3. Set up newly created objects
For a prefab, add the Storage Sync Object component. It restores marked fields early and captures their final values when the object is disabled.
Without that component, automatic discovery picks the script up on the next runtime update. Its Awake or Start may have already run.
If your script needs the value inside Awake, register at the start of that method:
private void Awake() => StorageSynchronization.Register(this);
Load your save normally when the game starts. The attribute connects fields to memory; it does not load a file by itself.
Choose keys carefully
player.health is shared by every instance using that key in the current profile. Use it for one shared player value, not for the separate health of every enemy.
Keep keys unchanged between game versions. Use different keys for independent values, and use the same field type wherever a key is shared.
More control
Supported fields and shared values
Public and private mutable fields work. Static, readonly, constant, nonserialized fields, empty IDs, and direct Unity object references are rejected. Values must follow the supported-type rules.
Multiple writers sharing a key use the last detected change. Prefer one writer. After switching profiles, fields use that profile's values on the next synchronization.
Manual synchronization and performance
StorageSynchronization.Synchronize()checks changes now.RestoreFromMemory()reapplies memory values.Unregister(target)captures and stops tracking an instance.
For explicit registration only, set StorageSyncRuntime.AutomaticDiscovery = false and register your objects yourself. Discovery uses scene queries; changes inside collections require extra comparison work. Keep frequently synchronized fields small and measure large data on your target device.
Build validation generates field/type preservation for IL2CPP. Test the actual stripped player before release.