Getting Started Must read
Make a data class
Create a script and inherit PersistentScriptableObject. Add
whatever serialized fields you want to persist, the same fields you
would put 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 you set in
[CreateAssetMenu]). This makes one PlayerData asset:
the single, 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: this is where and how the data is saved. Choose Prototype.
Prototype is the zero-configuration option: it just works, on desktop, mobile and WebGL, with nothing to set up. It is the recommended way to start. When you later want a specific manager (a real save file, Player Prefs, the cloud), you swap this dropdown without touching your code. See Local Saving for the full list.
Press Play
That is everything. 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.
No call to Save or Load anywhere. By default the
manager loads on launch and saves when the game stops, so the round trip is
automatic. You can also drive it yourself when you need to (see
Core Concepts).
Wiping your test data
Prototype is deliberately hands-off: it manages the save for you, so you never deal with files or paths. The one thing worth knowing while iterating is how to clear it, to retest the first-launch experience. Open Tools > Persistent Asset > Actions > Delete Local Data and pick the Prototype manager (or All).
What just happened?
Three pieces did the work, and you only had to set up the first two:
- Your data: the
PlayerDataobject you wrote. - A manager: Prototype, the one you picked in the dropdown. It saves and restores the object's fields.
- The operations: a load when the game starts and a save when it stops, both run for you.