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.
The component, in one screen#
- Select the object whose state matters — a door, a chest, a checkpoint.
- Add Component → PersistKit → PersistKit Behaviour.
- The component lists the object's components and, under each, the fields it can store.
- 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.
- Set the key it saves under (the default is built from the object's name).
- 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#
| Component | What can be remembered |
|---|---|
Transform | position and rotation, with a World space switch, or local space |
RectTransform | anchored position and size |
Rigidbody, Rigidbody2D | position, rotation, velocity, angular velocity, body type, gravity, damping, constraints — written through the physics body, so the next physics step does not undo it |
Animator | its float, int and bool parameters. Never its triggers: a trigger is an event, not a state |
Collider, Collider2D, CharacterController | enabled, and the parts that change at run time |
AudioSource | volume, mute, pitch |
| Your own scripts | the 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#
| Moment | What happens |
|---|---|
Start | loads, once the scene exists |
OnDisable / OnDestroy | saves, so a door that is opened stays open |
OnApplicationPause, OnApplicationQuit | saves on the way out, where the platform allows it |
| Your own call | SaveNow() 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:
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