Skip to content

antonholmquist/easy-serializer-unity

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 

Easy Serializer for Unity

This project aims to make object serialization in Unity as simple as possible while supporting all platforms.

Platform Support

PC/Mac/Linux standalones, iOS, Android.

Usage

1. Preparing the object for serialization

First, you need to make sure that the class you want to serialize adheres to one of the two following:

  • For automatically serialization, mark the class with the SerializableAttribute as in ExampleObjectSerializableAttribute.cs.

  • For a fine-grained serialization process, implement the ISerializable interface as in ExampleObjectISerializable.cs.

2. Serialization / Deserialization

Serialize object to file

EasySerializer.SerializeObjectToFile(serializableObject, filePath);

Deserialize object from file

Object anObject = EasySerializer.DeserializeObjectFromFile(filePath);

Unity Persistent File Path

In case you didn't already know, a persistent file path can be aquired in Unity like this:

string filePath = Application.persistentDataPath + '/object.data';

Protip: iOS JIT Exception Fix

Standard object serializing in Unity on iOS devices breaks with this exception: ExecutionEngineException: Attempting to JIT compile method 'List 1__TypeMetadata:.ctor ()' while running with --aot-only..

To avoid this in your own code, add this line before doing any serialization it should work:

Environment.SetEnvironmentVariable("MONO_REFLECTION_SERIALIZER", "yes");

Author

Anton Holmquist

About

Easy serialization in Unity supporting all platforms

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages