Save your own game data

For an inventory, quest log, or player checkpoint, put the values you need in a small data class. Your scene script can implement ISaveable<TState>:

  • CaptureState() returns the values you want to remember.
  • RestoreState(state) applies those values to your game.

Call these methods when saving and loading. Implementing the interface alone does not make the component save automatically.

// Save the inventory's current values.
SaveSystem.Set("player.inventory", inventory.CaptureState());
SaveResult saved = await SaveSystem.SaveAsync();

// Load those values and apply them to the inventory.
SaveResult loaded = await SaveSystem.LoadAsync();
if (loaded.Succeeded &&
    SaveSystem.TryGet<InventoryState>("player.inventory", out var state))
    inventory.RestoreState(state);

See Examples/02-QuickStart/InventoryExample.cs for the complete data class and component. When capturing a list, make a copy so later gameplay changes do not change your checkpoint.

Keep custom data readable after a rename

Give each custom data type a stable name. Register it before loading:

SaveTypeRegistry.Register<PlayerState>("game.player.v1");

Keep this ID when you rename or move the C# class. If you have already changed an ID, pass its old name as an additional argument.

Save a type that needs special handling

Most data classes work with public fields. For a type that needs a different representation, add a Newtonsoft JsonConverter through JsonSaveSerializer.AddConverter.

Advanced: replace the serializer

Assign an ISaveSerializer to SaveServices.Serializer before saving or loading. It converts objects to JSON and reads JSON with an explicit target type.

Produce consistent output for the same data because change detection uses serialized checksums. The default serializer uses TypeNameHandling.None; keep arbitrary type-name deserialization disabled for untrusted data.

Choose a different storage location

To change only the save folder, use the configurator's storageDirectory setting. To store data somewhere else entirely, supply your own ISaveStorage.

Start with Examples/02-QuickStart/MemoryStorageExample.cs. This example keeps bytes in memory, so they disappear when the game closes.

Advanced: implement a storage provider

Assign your provider to SaveServices.Storage before saving or loading. Implement Exists, Read, Write, Delete, and FlushAsync.

Protect the previous file until a replacement is ready, honor the overwrite flag, and complete FlushAsync only when storage has finished. Copy mutable byte arrays and support the threading mode of your target platform.

Other extension points

Use ISaveMigration to update older game data, or ICloudSaveProvider to connect another cloud service.

Advanced: service and assembly integration

SaveServices exposes the storage, serializer, cloud provider, schema version, and migration collection. Configure these before IO begins.

Source integration scripts call the compiled implementation. Direct DLL consumers must provide configuration snapshots and host integration; the implementation does not reference the source wrappers.