book-openPublic API

This document covers the public API for Crystal Save, a comprehensive save system for Unity with support for local storage, cloud backends (Supabase, Firebase, Unity Cloud Save, MySQL), encryption, compression, and screenshot capture.


Common Use Cases (FAQ)

Loading Without a Scene Reload

Q: Can I load a saved slot without reloading the scene?

Yes! Set restoreLastActiveScene to false. This loads and restores all saved component data, prefabs, and GameObject states without triggering a scene change:

// Load slot 1 without changing scenes - restores all data in-place
SaveManager.Instance.Load(1, restoreLastActiveScene: false);

// Or with async version
LoadResult result = await SaveManager.Instance.LoadSaveSlotAsync(
    slotNumber: 1,
    restoreLastActiveScene: false  // Key parameter!
);

This is useful when:

  • Your game uses a persistent scene architecture

  • You want to restore player progress without a loading screen

  • You're implementing a "revert to checkpoint" feature within the same scene


Hooking Into Load Completion Events

Q: How can I run my own code after a save slot is successfully loaded?

Subscribe to the OnLoadCompleted event. This fires after all data has been restored, making it the perfect place to re-wire references in your GameManager:

Available Event Args Properties

Event
Args Type
Properties

OnLoadCompleted

SaveLoadEventArgs

Slot (SaveSlot), Success (bool), Message (string)

OnLoadFailed

OperationFailedEventArgs

Slot (SaveSlot), Operation (string), ErrorMessage (string)

OnSaveCompleted

SaveLoadEventArgs

Slot (SaveSlot), Success (bool), Message (string)

OnSaveFailed

OperationFailedEventArgs

Slot (SaveSlot), Operation (string), ErrorMessage (string)


Getting Started

Crystal Save uses a singleton pattern. Access the save manager via:

Initialization

The SaveManager initializes automatically on Awake(). You can check if it's ready:

Or subscribe to the initialization event:


SaveManager Singleton

Properties

Property
Type
Description

Instance

SaveManager

Static singleton instance

IsInitialized

bool

Returns true when the manager is fully initialized

CurrentSaveSlot

SaveSlot

The currently active save slot

CurrentSaveData

SaveData

The current in-memory save data

SaveSettings

SaveSettings

The active save settings configuration

AreSaveSlotsReady

bool (static)

True once save slots have been initialized

AreQuickSlotsReady

bool (static)

True once quick save slots have been initialized


Save Operations

Save (Fire-and-Forget)

Parameters

Parameter
Type
Description

slotNumber

int

The slot number to save to (1-based)

lastActiveScene

string

The scene name to restore on load

slotName

string

(Optional) Custom name for the save slot

SaveAsync (Awaitable)

SaveSync (Synchronous)

SaveImmediateAsync (No Delay)

Performs an immediate save without any batching or delay:


Load Operations

Load (Fire-and-Forget)

Parameters

Parameter
Type
Default
Description

slotNumber

int

-

The slot number to load

restoreLastActiveScene

bool

false

Whether to load the saved scene

loadAsync

bool

false

Use async scene loading

allowSceneActivation

bool

true

Allow scene activation when loaded

LoadSaveSlotAsync (Awaitable with Result)

LoadSaveDataForSlotAsync (Data Only, No Scene Change)

Load save data without triggering a scene change:


Quick Save & Auto Save

Quick Save

Quick Load

Auto Save

Auto Load


Slot Management

Get Save Slots

Check for Saves

Note: When cloud save is enabled, prefer async methods to avoid blocking the main thread.

Rename Save Slot

Delete Save Slot

Get Slot Metadata

Refresh Slots

Force a refresh of slot data from both local and remote sources:


Screenshot Management

Get Screenshot

Capture Screenshot Manually

Cleanup Unused Screenshots


Scene Transitions & Prefabs

Load Scene with Snapshot (In-Memory)

Load a scene while preserving prefab state in memory (no disk write):

Load Scene After Save and Populate

Save to a slot, populate pending prefabs, then load a scene:

Snapshot-Based Scene Transition (No Disk Write)

Create an in-memory snapshot and populate pending prefabs, then load a scene:

Snapshot Current Data

Capture the current game state in memory without writing to disk:

Snapshot and Populate

Capture game state and prepare pending prefabs for scene transitions:

Populate Pending Prefabs

Populate prefab data from a save slot (useful for custom scene loaders):


Single GameObject Restoration

Restore individual GameObjects without a full load operation.

From Current Save Data

From a Specific Slot

Restore Multiple GameObjects

Restore All Destroyed GameObjects


Events

Initialization Events

Save/Load Completion Events

Failure Events

Scene Loading Events

Screenshot Events

Slot Update Events

GameObject Restoration Events

Scene Activation Pipeline

Control when prefabs spawn during scene activation:


Extension Methods

Extension methods are available in the Arawn.CrystalSave.Runtime namespace.

Reset All Save Slots

Get Active Save Slots

Save to All Slots

Load Most Recent Slot

Restore from Most Recent Slot


Diagnostics & Utilities

Get Load State Diagnostics

Output example:

Get Pending Prefab Info

Validate Scene Loading Timing

Clear Pending Prefabs

⚠️ Warning: This permanently discards queued prefabs!


Scene Load Orchestrator

For advanced scene loading scenarios (Addressables, asset bundles), register a custom orchestrator:


SaveSlot Class

The SaveSlot class represents metadata for a save slot.

Properties

Property
Type
Description

SlotNumber

int

The slot number (1-based)

SlotName

string

The display name of the slot

LastSaved

DateTime

When the slot was last saved

LastActiveScene

string

The scene name at time of save

ScreenshotFileName

string

Path to the screenshot file

CustomMetadata

Dictionary<string, string>

Custom key-value metadata


LoadResult Struct

Returned by async load operations.

Properties

Property
Type
Description

Success

bool

Whether the load succeeded

ErrorMessage

string

Error message if failed (null on success)


Best Practices

  1. Use Async Methods with Cloud Save: When cloud save is enabled, always prefer *Async methods to avoid blocking the main thread.

  2. Wait for Initialization: Always check IsInitialized or subscribe to Initialized before performing operations.

  3. Handle Failures: Subscribe to failure events to provide user feedback when operations fail.

  4. Scene Transitions: Use LoadSceneAfterSnapshotAndPopulatePendingPrefabsAsync for seamless scene transitions with prefab persistence.

  5. Screenshots: Use OnScreenshotCaptureStarted and OnScreenshotCaptureFinished to hide/show UI elements.

  6. Diagnostics: Use GetLoadStateDiagnostics() when debugging scene loading issues.


Version Compatibility

  • Unity: 2022.3 LTS and Unity 6+

  • Serialization: MemoryPack

  • Cloud Backends: Supabase, Firebase, Unity Cloud Save, MySQL

Last updated