Controlling serialization using ES3Types

An ES3Type script tells Easy Save what fields and properties of a type to save and how to save them. This can be created automatically, and modified if necessary.

Once the script is created, Easy Save will automatically find it and use it to serialize and de-serialize your type. You do not need to create an instance of the ES3Type.

An ES3Type can be created by going to the Window > Easy Save 3, and selecting the Types tab.

From here you can select your Type from the list and choose the fields and properties you wish to save.

  • Note that all fields and properties are shown regardless of whether they are marked with the [Serializable] attribute.
  • Sometimes trying to save a property can have undesired effects.
    • So it’s recommended that you ensure it’s safe to serialize a property before selecting it.

In some cases you will need to modify the ES3Type. For example:

  • When the type does not have a parameterless constructor.
  • When you need to call a method to access the variable you’re saving/loading.

You can do this by modifying the Write, Read and ReadInto methods of the ES3Type script generated in the Types pane. The ES3Type script can be found in /Assets/Easy Save 3/Types/.

Note that once you manually modify the ES3Type file, any changes made in the Types panel will overwrite your manual modifications.

Modifying the Write method

You can change what properties are written by modifying or adding reader.WriteProperty calls in the Write method.

Note that UnityEngine.Object types such as MonoBehaviours and ScriptableObjects will be written by reference.

Modifying the Read method

The Read method uses the reader.Properties enumerator to get the name of each property, and a switch statement with reader.Read calls to read the value of that property.

By changing or adding cases in the switch statement you can change which properties are serialized.