Saving

This section outlines the step-by-step process of saving 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

The first step to saving data is getting the save file. This can be done by getting the save file setup component first, which will give you access to the save file with SaveFileSetup.GetSaveFile.

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

It's recommended to use this code in Awake or Start.

2. Saving Data

Each piece of data in a save file has an ID (string). This makes it possible to retrieve specific data by ID.

Saving data can be done with a single line with SaveFile.AddOrUpdateData.

saveFile.AddOrUpdateData("DataID", data);

The first parameter is the ID of the data, and the second parameter is the data itself. Any serializable data type can be saved. However, most Unity types are not savable. ESave can save common Unity data types, including (but not limited to) Vector2, Vector3, Quaternion, Color, and Transform.

Remember to use SaveFile.Save to officially save the data in the user's system.

saveFile.Save();

Last updated