Loading

This section outlines the step-by-step process of loading data using ESave.

You may need to code a bit differently if you have background task enabled. See Understanding Background Save & Load

1. Getting the Save File

Just like saving, you need a reference to a save file to load data.

saveFileSetup = GetComponent<SaveFileSetup>();
saveFile = saveFileSetup.GetSaveFile();

2. Loading Data

Each ESave method that loads data only accepts one parameter, which is the ID of the data.

GetData

The main method to load data is SaveFile.GetData. This method accepts any type parameter.

// Where T is the data type
T data = saveFile.GetData<T>("DataID");

You can also retrieve a list of data of the same type:

// Where T is the data type
List<T> dataList = saveFile.GetData<T>("DataID", "DataID2", "DataID3");

Special Methods

ESave features special methods to retrieve data for some Unity types.

Vector2

Vector2 v2 = saveFile.GetVector2("DataID");

Vector3

Vector3 v3 = saveFile.GetVector3("DataID");

Quaternion

Quaternion q = saveFile.GetQuaternion("DataID");

Color

Color c = saveFile.GetColor("DataID");

Transform

// Returns a SavableTransform
SavableTransform st = saveFile.GetTransform("DataID");

// Use Transform.CopyTransformValues to set values from a 
// SavableTransform to a Transform
transform.CopyTransformValues(st);

Last updated