Basic Saving and Loading
Looking for how to use Easy Save with Playmaker? Take a look at our Playmaker Guide.
Saving Variables and Components
To save variables, we use ES2.Save(variable, path).
The first parameter is the variable we want to save, and it must be a variable on the Supported Types list.
The second parameter is a path which we use to identify the data we are saving. This could be a simple name, a filename, a path to a file and many other things.
C#
1 2 3 4 |
/* Save the value 123 to a key named myInt */ ES2.Save(123, "myInt"); /* Save this transform to a file named File.txt */ ES2.Save(this.transform, "File.txt"); |
JS
1 2 3 4 |
/* Save the value 123 to a key named myInt */ ES2.Save(123, "myInt"); /* Save this transform to a file named File.txt */ ES2.Save(this.transform, "File.txt"); |
Loading Variables
You load variables using ES2.Load<Type>(path), where ‘Type’ is the type of variable you are loading. You should use the same path as you used to save the data.
If you are not sure whether there will be data to load or not, you should use ES2.Exists(path) before hand to check if the data exists.
C#
1 2 3 4 |
/* Check that there is data to load */ if(ES2.Exists("myInt")) /* Load the int we saved into myInt */ myInt = ES2.Load<int>("myInt"); |
JS
1 2 3 4 |
/* Check that there is data to load */ if(ES2.Exists("myInt")) /* Load the int we saved into myInt */ myInt = ES2.Load.<int>("myInt"); |
Loading Components
Because of the way Components work in Unity, we should provide Easy Save with a Component to load our data into.
We do this using the self-assigning load method: ES2.Load(path, component).
C#
1 2 3 |
/* Load the Transform we saved into the Transform of this object */ if(ES2.Exists("myTransform")) ES2.Load<Transform>("myTransform", this.transform); |
JS
1 2 3 |
/* Load the Transform we saved into the Transform of this object */ if(ES2.Exists("myTransform")) ES2.Load.<Transform>("myTransform", this.transform); |