Saving a scene object without code

The PersistKit Behaviour component — tick the parts of an object that should come back after a restart, with no script to write.

Get started NexusForge Persistence 1.0.0 Updated

The component, in one screen#

  1. Select the object whose state matters — a door, a chest, a checkpoint.
  2. Add Component → PersistKit → PersistKit Behaviour.
  3. The component lists the object's components and, under each, the fields it can store.
  4. Tick what should be saved and what should be loaded. The two are separate on purpose: a value can be written without ever being overwritten, or read from an older save without being rewritten.
  5. Set the key it saves under (the default is built from the object's name).
  6. Press Play. Nothing else is needed: the component saves when the object is disabled or destroyed, when the application pauses or quits, and loads when the scene starts.

What each Unity component offers#

ComponentWhat can be remembered
Transformposition and rotation, with a World space switch, or local space
RectTransformanchored position and size
Rigidbody, Rigidbody2Dposition, rotation, velocity, angular velocity, body type, gravity, damping, constraints — written through the physics body, so the next physics step does not undo it
Animatorits float, int and bool parameters. Never its triggers: a trigger is an event, not a state
Collider, Collider2D, CharacterControllerenabled, and the parts that change at run time
AudioSourcevolume, mute, pitch
Your own scriptsthe public fields Unity itself serializes

A field with a type PersistKit cannot store is left out and named, rather than saved as nothing. If you ticked it on purpose, the save is refused with PK-TYPE-001 instead — asking for something and quietly not getting it would be the one failure this package exists to avoid.

Fields that point at an asset#

A field holding a Sprite, a ScriptableObject or a prefab is offered too. It is stored as the key the asset is registered under, so it can be found again in a player build. One click registers it — see the asset registry.

A field that points at an object in the scene is refused, with the fix in the message: give that object a PersistKit Identity and save it under its own key. An identity is what makes a scene object findable again; without one there is nothing stable to write down.

When it saves and loads#

MomentWhat happens
Startloads, once the scene exists
OnDisable / OnDestroysaves, so a door that is opened stays open
OnApplicationPause, OnApplicationQuitsaves on the way out, where the platform allows it
Your own callSaveNow() and LoadNow() on the component, for a checkpoint of your own

Platforms are not all the same here: a mobile app can be killed without warning, and a console can suspend the game. Documentation~/no-code-component.md in the package says exactly which moment each platform guarantees.

Using it from code#

The component's key is an ordinary save key, so the game's own code can read the same data:

csharp
var doors = FindObjectsByType<PersistKitBehaviour>(FindObjectsSortMode.None);

foreach (var door in doors)
{
    door.SaveNow();     // at a checkpoint, say
    door.LoadNow();
}

Next#

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