Getting Started Must read
Make a data class
Create a script and inherit PersistentScriptableObject. Add the
serialized fields you want to persist, exactly as on any
ScriptableObject.
using PersistentAsset;
using UnityEngine;
[CreateAssetMenu(menuName = "Player Data")]
public class PlayerData : PersistentScriptableObject
{
public int gold;
public int level = 1;
}
Create the asset
In the Project window, right-click and choose
Create > Player Data (the menu name set in
[CreateAssetMenu]). This makes one PlayerData asset:
the shared instance your game reads and writes at runtime.
Reference it like any ScriptableObject: a serialized field on a MonoBehaviour, a
Resources.Load, or your own dependency setup.
Pick a manager
Select the asset. At the top of its inspector is a Persistence Manager dropdown, which sets where and how the data is saved. Choose Prototype.
Prototype needs no configuration and works on desktop, mobile and WebGL. Moving to another manager later (a real save file, Player Prefs, the cloud) is a change of dropdown, with no code to touch. See Local Saving for the full list.
Press Play
To see it work:
- Enter Play mode.
- Change
goldat runtime, from your code, or by editing the asset in the inspector while playing. - Exit Play mode. Persistent Asset saves automatically.
- Enter Play mode again, and
goldis loaded back to the value you left it at.
There is no call to Save or Load anywhere: the manager
loads on launch and saves when the game stops. Both can also be called manually
(see Core Concepts).
Wiping your test data
To retest the first-launch experience, open Tools > Persistent Asset > Actions > Delete Local Data and pick the Prototype manager (or All). Prototype handles its own file, so there is no path to find.
What just happened?
Three pieces did the work:
- Your data: the
PlayerDataobject. - A manager: Prototype, picked in the dropdown. It saves and restores the object's fields.
- The operations: a load when the game starts, a save when it stops, both automatic.