ESave
ESave Pro
ESave Pro
  • ESave Pro Documentation
  • Pro Comparison
  • πŸ•ΉοΈGetting Started
    • Installation
    • Demo
  • ESave Settings
  • 🧩Components
    • ESave Initializer
  • πŸ“„Scripting
    • Initialization
    • Save Operation
    • Save States
      • Infinite Saves
        • Infinite Save Scripting
    • Saving & Loading Data
      • Saving
      • Loading
      • Custom Serializable Objects
      • Example Script
    • Data Deletion
  • πŸ› οΈSupport
    • Getting Help
  • πŸ“šChangelogs
    • Latest Releases
  • ⭐Rate Me?
Powered by GitBook
On this page
  • Active Save State
  • Creating New Saves
  • Checking Existing Saves
  • Getting Save States
  • Loading Save States
  • Saving Save States
  1. Scripting

Save States

Working with save states.

Active Save State

It's important to understand what the active save state is before continuing. The active save state acts as a temporary copy that updates as the player progresses through the game. Instead of modifying the original save file directly, all changes are made to this active copy. The original save remains unchanged unless the player explicitly chooses to save, ensuring that it can be reloaded in its unedited state if needed.

Creating New Saves

New save states require a unique integer ID. That's all you really needβ€”but even that isn't necessary to manage yourself. Save state IDs are auto-incremented to ensure they are all unique. However, you can still create a save state with a specific ID.

Use the ESave.CreateSave method to create a new save. If an ID parameter is not passed, the ID will be automatically generated.

ESave.CreateSave();

This method returns a Save Operation (result type: SaveState).

To create a new save state with a specific ID, simply pass it as a parameter. In the code below, a new save with the ID 0 will be created if an existing one with the ID doesn't exist. If there is another save with the same ID, the existing save will be returned instead.

ESave.CreateSave(0);

Checking Existing Saves

Use the HasSave method to simply check if a save with a specific ID exists.

int id = 0;
bool result = ESave.HasSave(id);

Getting Save States

Active

You can get the active save state with the SaveState.active field.

By ID

You can get a save state with the ESave.GetSaveState method.

var saveState = ESave.GetSaveState(mySaveStateID);

Getting All Save States

To get a list of all save states, use ESave.GetAllSaveStates.

ESave.GetAllSaveStates().OnComplete(allSaveStates =>
{
    Debug.Log(allSaveStates.Count);
});

This method returns a Save Operation (result type: List<SaveState>).

Loading Save States

You can load a save state by passing its ID in the ESave.Load method. This will set the loaded save state as active.

ESave.Load(mySaveStateID);

This method returns a Save Operation (result type: SaveState).

Saving Save States

To save all data of the active save state (the temporary copy) into the original save state, call ESave.Save.

ESave.Save();

If an int (save state ID) or SaveState parameter is passed, the active save state will instead store its data into the save state of your choice. Either way, the targeted save state's data is completely overwritten by the active save state data.

This method returns a Save Operation (result type: SaveState).

PreviousSave OperationNextInfinite Saves

Last updated 2 months ago

πŸ“„