Choosing individual fields
The Save and Load columns — write a value without overwriting it, read an old value without rewriting it, and keep two components apart.
Two columns, two questions#
Every field in the Inspector has a Save box and a Load box. They answer different questions, and the combination is what makes a save file behave the way a game needs it to:
| Save | Load | What it does |
|---|---|---|
| ✓ | ✓ | Ordinary: the value is written on save and put back on load |
| ✓ | Written every time, never overwritten on load — for a value the game decides | |
| ✓ | Read from an older save, never rewritten — for a value that should not change once set | |
| Not in the file at all |
A field that is not ticked is not written at all. That is the difference between "nothing happened" and "the file holds a value that will never be applied", and it is why an unticked field cannot surprise you later.
What is actually stored#
One entry per component, holding three parallel arrays: the field paths, the kind of each value, and the values. The field's kind is recorded as well as its value, so a field whose type changed between two builds of your game is refused with PK-VALUE-001 and left alone, rather than forced into the new type.
The same thing from code#
var fields = new PersistKitFieldSet { chosen = true };
fields.Set(class="tok-str">"m_LocalPosition.x", save: true, load: true);
fields.Set(class="tok-str">"m_LocalScale.x", save: true, load: false); // written, never restored
Persist.SaveComponentFields(class="tok-str">"lamp", transform, fields);
Persist.LoadComponentFields(class="tok-str">"lamp", transform, fields);Persist.LoadComponent reads a chosen-field save too, applying every field the file holds, which is what makes the key shown in the Inspector usable from the game's own code.
Two components, two sets of fields#
A save belongs to the component it came from. Two PersistKitBehaviour components on one object — or the same component type on two different objects — keep their own keys and their own field lists, and loading one never touches the other.
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