Saving

How to save data to SaveStates.

Single

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

Saving data can be done with a single line with the AddData method.

saveState.AddData("MyDataID", 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, Vector4, Quaternion, Color, Transform, and RectTransform.

This method returns a Save Operation (result type: bool). The result is true if the data was successfully added. Otherwise, false.

Multiple

You can use the AddData method to save multiple data with one call. This can be done by providing the data as a value tuple with a string as the first item and the data as the second.

saveState.AddData(("MyDataID1", myData1), ("MyDataID2", myData2));

This method returns a Save Operation (result type: bool). The result is true if all provided data was added successfully. If even one fails to be added, the result is false.

Last updated