API Reference

All types live in the WaggleBum.WagSave namespace unless otherwise noted.

using WaggleBum.WagSave;
using WaggleBum.WagSave.Core.SaveSlots; // SaveSlot, SaveSlotManager
using WaggleBum.WagSave.Core.Enums;    // SaveSlotType, LogLevel

Getting an Instance

// Get the active (or only) WagSave instance
WagSave wagSave = WagSave.GetInstance();

// Get a specific instance by its ID (useful when multiple instances exist)
WagSave wagSave = WagSave.GetInstance("my-instance-id");

// Get all instances in the project
WagSave[] all = WagSave.GetAllInstances();

At runtime in builds, GetInstance loads from Resources/WagSave/. In the editor it uses AssetDatabase. If no instance is found, null is returned and a warning is logged.


Component Save / Load

These methods save and load all WagSaveComponent instances across every currently loaded scene.

Synchronous

// Save all components — optionally into a specific slot
wagSave.Save();
wagSave.Save(slot);

// Load all components — optionally from a specific slot
wagSave.Load();
wagSave.Load(slot);

Asynchronous (recommended)

Serialization and file I/O run on a background thread. Unity API calls remain on the main thread.

await wagSave.SaveAsync();
await wagSave.SaveAsync(slot);

await wagSave.LoadAsync();
await wagSave.LoadAsync(slot);

Behaviour when Save Slots are enabled

When Save Slots are enabled and no slot argument is provided:

  • If Use Save Slot UI is on, the built-in slot selection UI is shown automatically.
  • If Use Save Slot UI is off, WagSave selects a slot automatically based on your configuration.

Pass an explicit slot to bypass UI and slot selection entirely.


Key-Value Save / Load

For saving individual values that are not tied to a specific GameObject.

// Static convenience — uses the active WagSave instance
WagSave.Save("score", 9500);
WagSave.Save("playerName", "Alex", groupName: "player");

// Typed load
int score = WagSave.Load<int>("score");
string name = WagSave.Load<string>("playerName", groupName: "player");

// Untyped load
object raw = WagSave.Load("score");

The optional groupName parameter namespaces keys to avoid collisions. The optional instanceId parameter targets a specific WagSave instance when multiple exist.


Autosave

// Fire an autosave immediately (sync)
wagSave.AutoSave();

// Fire an autosave immediately (async)
await wagSave.AutoSaveAsync();

// Pause the autosave timer
wagSave.PauseAutoSave();

// Resume a paused autosave timer (resets the countdown)
wagSave.ResumeAutoSave();

// Reset the autosave countdown without pausing
wagSave.ResetAutoSaveTimer();

// Pin a specific slot to be used by the next autosave
wagSave.SetAutoSaveSlot(slot);

// Clear the pinned slot so autosave selects automatically again
wagSave.ClearAutoSaveSlot();

The autosave timer itself is driven by WagSaveManager — a MonoBehaviour that must be present in the scene. See Autosave.


Properties

PropertyTypeDescription
IsSavingboolTrue while a save operation is in progress.
IsLoadingboolTrue while a load operation is in progress.
ProgressintCurrent operation progress, 0–100.
SettingsWagSaveSettingsAccess to all configuration settings.
SaveSlotsSaveSlotManagerThe save slot manager. See Save Slots.
IsSaveOverrideEnabledboolTrue when both OnSaveOverride and OnLoadOverride are subscribed.
DebugLogLevelLogLevelMinimum log severity written to the Unity Console.
LogToFileEnabledboolWhen true, log output is also written to a file.
InstanceCountintNumber of WagSave assets found in the project.

Events

Subscribe to events on the WagSave instance to react to save/load lifecycle changes.

private void OnEnable()
{
    var wagSave = WagSave.GetInstance();
    wagSave.OnSaveStart     += HandleSaveStart;
    wagSave.OnSaveCompleted += HandleSaveCompleted;
    wagSave.OnLoadStart     += HandleLoadStart;
    wagSave.OnLoadCompleted += HandleLoadCompleted;
    wagSave.OnProgress      += HandleProgress;
    wagSave.OnError         += HandleError;
}

private void OnDisable()
{
    var wagSave = WagSave.GetInstance();
    if (wagSave == null) return;
    wagSave.OnSaveStart     -= HandleSaveStart;
    wagSave.OnSaveCompleted -= HandleSaveCompleted;
    wagSave.OnLoadStart     -= HandleLoadStart;
    wagSave.OnLoadCompleted -= HandleLoadCompleted;
    wagSave.OnProgress      -= HandleProgress;
    wagSave.OnError         -= HandleError;
}

private void HandleSaveStart()    { Debug.Log("Save started"); }
private void HandleSaveCompleted(){ Debug.Log("Save complete"); }
private void HandleLoadStart()    { Debug.Log("Load started"); }
private void HandleLoadCompleted(){ Debug.Log("Load complete"); }
private void HandleProgress(int percent) { Debug.Log($"Progress: {percent}%"); }
private void HandleError(string message, Exception ex) { Debug.LogError(message); }

Full Event Reference

EventSignatureRaised When
OnSaveStart() => voidImmediately before a save begins.
OnSaveCompleted() => voidAfter a save finishes successfully.
OnLoadStart() => voidImmediately before a load begins.
OnLoadCompleted() => voidAfter a load finishes successfully.
OnProgress(int percent) => voidPeriodically during save or load with 0–100 completion.
OnError(string msg, Exception ex) => voidWhen a save or load error occurs.
OnAutoSaveTimer(int secondsRemaining, int interval) => voidEach frame during an active autosave countdown.
OnAutosavePause() => voidWhen autosave is paused.
OnAutosaveResume() => voidWhen autosave is resumed.
OnAutosaveTimerReset() => voidWhen the autosave countdown is reset.
OnGetEncryptionPrivateKeySee ExtensibilityWhen an encrypted save needs the private key.
OnSaveOverrideSee ExtensibilityCustom serialization — replaces default save logic.
OnLoadOverrideSee ExtensibilityCustom deserialization — replaces default load logic.

Multiple Instances

If your project has more than one WagSave asset (e.g. separate profiles for game data and settings), mark one as Active in the editor or call:

wagSave.SetActive(); // marks this instance active, deactivates all others

GetInstance() without arguments returns the active instance. To get a specific one:

WagSave settingsSave = WagSave.GetInstance("settings-instance-id");

The instance ID is shown in the WagSave editor window header and stored on the asset.