Asset references

The asset registry — how a save file points at a Sprite, a ScriptableObject or a prefab and finds it again in a player build.

Unity objects NexusForge Persistence 1.0.0 Updated

Why a table is needed#

A save file cannot hold a Unity object, and it cannot hold an asset path (a path is an editor idea and does not exist in a player build), or a GUID (nothing at run time can turn one back into an asset without a table), or an instance id (that changes every time the game runs). So the table is the honest answer:

text
save file        the registry                 the build
---------        -------------                ---------
"lantern"   ->   "lantern" -> Lantern.prefab -> the asset itself

The key is authored data, so it is the same in every build and on every machine.

Setting one up#

  1. Tools → PersistKit → Asset Registry. The registry asset is created the first time you ask for it, in the folder the runtime looks in: Resources/PersistKit/PersistKit Asset Registry.
  2. Select an asset in the Project window and Tools → PersistKit → Register Selection in the Asset Registry, or press Register this asset on the field that holds it. A short key is suggested from the asset's name.
  3. That key is what a save file will hold.

A game that keeps its assets somewhere else — an Addressables catalog, a manager object, its own settings file — can assign PersistKitAssetRegistry.Instance before the first save, and nothing in Resources is looked at. That is the whole seam: one property.

Using it#

csharp
Persist.Save(class="tok-str">"selected-skin", spriteAsset);

Sprite skin = Persist.LoadReference<Sprite>(class="tok-str">"selected-skin", null);

if (skin == null)
{
    Debug.LogWarning(Persist.LastResult);   // PK-REF-005: this build cannot resolve that key
}

The kind of asset you ask for has to be the kind that was saved: asking for a Sprite when the key holds a prefab is refused with PK-VALUE-001, not cast to something plausible.

When a key cannot be resolved#

CodeWhat it meansWhat to do
PK-REF-004The asset has no keyRegister it: press Register this asset, or add it to the registry
PK-REF-005This build's registry has no such key, or the entry is emptyThe asset was left out of the build, or the registry in this build is a different one
PK-REF-006One key names two assets, or one asset has two keysKeep one key per asset: the editor validation lists the pair
PK-REF-007That key is not something that can be made into a scene objectIt was used where a prefab was expected

The editor validation pass (Tools → PersistKit → Validate Scene and References) reports all four, plus saved asset keys this project cannot resolve.

Next#

Addressables#

Not supported The package resolves assets through the registry, which works with a plain Resources folder or with any table you supply through PersistKitAssetRegistry.Instance. An Addressables-aware resolver of your own can be set through that same property; PersistKit does not ship one, and does not depend on the Addressables package.

Something wrong on this page? Every page here describes behaviour that is checked in the repository. If a page and the package disagree, the package wins.

Report a documentation problem · Error codes · Platforms and limitations