Supported Types

Most custom types can be supported by creating an ES2Type for it, either automatically using Manage Types… or manually using a template.

For information on how to do this, please see the Adding Support for Other Types guide.

  • int
  • float
  • string
  • byte
  • bool
  • char
  • long
  • short
  • uint
  • ulong
  • ushort
  • Enum
  • DateTime

Note: Saving collections containing collections is not directly supported, but can be achieved with the ‘Saving Nested Collections’ guide.

  • Array [ ]
  • 2D Array [,]
  • 3D Array [,,]
  • Dictionary<TKey, TValue>
  • List<T>
  • Queue<T>
  • HashSet<T>
  • Stack<T>

Click a type to see what variables it saves.

 

Vector2
  • x
  • y
Vector3
  • x
  • y
  • z
Vector4
  • x
  • y
  • z
  • w
Quaternion
  • x
  • y
  • z
  • w
Color
  • r
  • g
  • b
  • a
Color32
  • r
  • g
  • b
  • a
Texture2D
  • pixels
  • filterMode
  • anisoLevel
  • wrapMode
  • mipMapBias
Sprite
  • texture
  • rect
  • bounds
  • textureRect
  • name
Material

Note: Textures are saved by value, not by reference.

  • Textures
  • shader
  • textureOffset
  • textureScale
Mesh

Note: Meshes are saved by value, not by reference.

  • submeshes
  • vertices
  • triangles
  • normals
  • uv
  • uv2
  • tangents
  • bindposes
  • boneWeights
  • colors32
AudioClip

Note: AudioClips are saved by value, not by reference.

Note 2: Data is saved in a raw format so this may not be suitable for long AudioClips.

  • name
  • samples
  • channels
  • frequency
Rect
  • x
  • y
  • width
  • height
Bounds
  • center
  • size
Matrix4x4
  • columns
BoneWeight
  • boneIndex0
  • boneIndex1
  • boneIndex2
  • boneIndex3
  • weight0
  • weight1
  • weight2
  • weight3

Click a type to see what variables it saves.

Transform

Note: Components are saved by value, not by reference.

  • position
  • rotation
  • localScale
  • tag
SphereCollider

Note: Components are saved by value, not by reference.

  • center
  • radius
  • isTrigger
BoxCollider

Note: Components are saved by value, not by reference.

  • center
  • size
  • isTrigger
CapsuleCollider

Note: Components are saved by value, not by reference.

  • center
  • radius
  • height
  • direction
  • isTrigger
MeshCollider

Note: Components are saved by value, not by reference.

  • sharedMesh
  • convex
  • smoothSphereCollisions
  • isTrigger

It’s not possible to save Collections which contain other collections due to limitations in C# / UnityScript.

However, an easy workaround is to create a wrapper class which contains your inner collection, and then add that as a supported type. You can then save a Collection of these wrapper classes.

For example, a wrapper class for an int array might look like this:

public class ArrayWrapper
{
    public int[] array;

    public static ArrayWrapper Create(int[] array)
    {
        ArrayWrapper wrapper = new ArrayWrapper();
        wrapper.array = array;
        return wrapper;
    }
}

We can then use this to store a List of arrays as follows:

List<ArrayWrapper> intArrayList = new List<ArrayWrapper>();
// Add some arrays to our List using the ArrayWrapper to wrap them.
intArrayList.Add( ArrayWrapper.Create( new int[]{1, 2, 3} ) );
intArrayList.Add( ArrayWrapper.Create( new int[]{4, 5, 6, 7, 8} ) );
intArrayList.Add( ArrayWrapper.Create( new int[]{9, 10} ) );

// Save our List.
ES2.Save(intArraylist, "myFile.txt?tag=intArrayList");

// Load our List.
intArrayList = ES2.LoadList<ArrayWrapper>("myFile.txt?tag=intArrayList");

We’ve created an ES2Type for saving and loading GameObjects, but is also provided here as an example.

It saves a GameObject and it’s supported Components. Note that this will not save the children of the GameObject.

After creating the ES2Type file below, you will need to refresh the type list by going to Assets > Easy Save 2 > Manage Types and pressing the Refresh ES2Init button.

using System.Collections.Generic;
using UnityEngine;
 
public sealed class ES2_GameObject : ES2Type
{
    public ES2_GameObject() : base(typeof(GameObject)) { }
 
    public override void Write(object data, ES2Writer writer)
    {
        GameObject go = (GameObject)data;
        // Get the Components of the GameObject that you want to save and save them.
        var components = go.GetComponents(typeof(Component));
        var supportedComponents = new List<Component>();
 
        // Get the supported Components and put them in a List.
        foreach (var component in components)
            if (ES2TypeManager.GetES2Type(component.GetType()) != null)
                supportedComponents.Add(component);
 
        // Write how many Components we're saving so we know when we're loading.
        writer.Write(supportedComponents.Count);
 
        // Save each Component individually.
        foreach (var component in supportedComponents)
        {
           var es2Type = ES2TypeManager.GetES2Type(component.GetType());
           writer.Write(es2Type.hash);
            es2Type.Write(component, writer);
        }
    }
 
    public override void Read(ES2Reader reader, object obj)
    {
        GameObject go = (GameObject)obj;
        // How many components do we need to load?
        int componentCount = reader.Read<int>();
 
        for (int i = 0; i < componentCount; i++)
       {
           // Get the ES2Type using the hash stored before the component.
          var es2Type = ES2TypeManager.GetES2Type(reader.Read<int>());
          // Get Component from GameObject, or add it if it doesn't have one.
         Component c = go.GetComponent (es2Type.type);
           if(c == null)
               c = go.AddComponent(es2Type.type);
          // Use the ES2Type to read.
         es2Type.Read(reader, c);
        }
    }
 
    public override object Read(ES2Reader reader)
    {
        GameObject go = new GameObject();
        Read(reader, go);
        return go;
    }
}