Automatic saving

Add automatic saving to a Unity game with one component — a timer, the moments worth saving at, and a checkpoint your own code can call.

PersistKit NexusForge Persistence 1.0.0 Updated

What it is#

PersistKit Auto Save is one component that saves while the game runs. It is the answer to "I do not want to think about when to save" — add it to an object in your first scene, and the game saves on a timer and at the moments that matter.

Available In the package and covered by tests, in the Editor and at runtime.

The settings#

SettingDefaultWhat it does
Automatic savingonThe master switch. Switching it off never unsaves anything — it only stops saves happening by themselves.
Save every … seconds300The timer. 0 turns the timer off and leaves the moments below working.
Save when the game is pausedonThe moment that matters on a phone, where a paused game can be ended by the system without ever reaching a quit message.
Save when the game loses focusoffOff by default: on a desktop, clicking another window is usually not a moment worth writing to disk.
Save when the game quitsonWhere the platform gives a game the chance.
Save remembered objectsonSaves every object in the scene with a PersistKit Behaviour on it.
Track playtimeonKeeps how long this save has been played, so a save menu can show it.
Save slotemptyEmpty means "whichever slot the game is using". Naming a slot keeps this component's saves separate.

The three Unity events under Saving are where your own data goes: BeforeSave, Save and AfterSave.

Asking for a save yourself#

Two calls, and they differ only in intent:

csharp
class="tok-com">// Save now: the same thing the timer does.
PersistResult result = autoSave.SaveNow();
class="tok-com">
// A checkpoint: a save the player just earned — after a boss, on leaving a level.
PersistResult reachedTheBossRoom = autoSave.Checkpoint();

Both report what happened through result, and the last one is also kept in LastResult and LastMessage.

What it guarantees#

  • One save at a time. A second request while a save is running waits; it does not start a second write.
  • One automatic save per frame. Two moments landing on the same frame are one save.
  • Nothing to save is reported, not hidden. If nothing has changed, the result says so instead of writing an empty file.
  • No network. Automatic saving never talks to a cloud service. A cloud copy is something you ask for.

How to know it is set up#

Select the component in the Inspector. PersistKit reads your settings back to you in plain words — when it will save, whether it has anything to save at all, and the two combinations that quietly never save anything. In Play mode the same panel shows the seconds until the next save and the result of the last one.

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