How should I serialize data that is also editable in the Inspector?

I have successfully achieved both of the requirements in isolation:

  1. Using a BinaryFormatter to serialize an arbitrary object, converting it to Base64, and storing it in the cloud. I can later download, convert to byte array, deserialize and cast to my type.
  2. Implementing a custom type that extends ScriptableObject that is fully editable in custom Inspector. Values are saved with the Scene, and generally working great. (Thanks to the Serialization Best Practices Megapost)

My problem is that I would like to take an instance of this Class that extends ScriptableObject and pass it through my serializer to store online. However I get the error that ScriptableObject is not marked as serializable.

SerializationException: Type UnityEngine.ScriptableObject in assembly UnityEngine, Version=, Culture=neutral, PublicKeyToken=null is not marked as serializable.

Has anyone come up with a method / pattern to achieve this functionality? Should I forgo the Unity serialization entirely and use my mechanism directly from the Editor? It seems like a very ugly solution to me, but its the only solution I can think of at the moment.

Thanks in advance

Edit: See VFW for a better/advanced serialization system

The thing is, you can’t use BinaryFormatter for UnityEngine.Objects because they’re not mocked with Serializable which is required by BinaryFormatter. I am also seeking optimal solutions for this - The problem is, even if say, you use an annotation-free serializer (like Migrant for example) you’re not guaranteed to get the object back safely upon deserialization - Because, for example let’s talk about Components, why doesn’t unity allow us to create them with the new operator but only with AddComponent? obviously, because Unity does some prepping/internal home cooking to build the component, things that not any serializer could figure out on its own.

The best way I found to serialize UnityEngine.Objects is to leave their serialization to unity itself, don’t bother.

If you want to serialize them to a readable format upload them to some server and download later, you could check out @whydoidoit’s awesome Unity Serializer.

A custom non-generic class marked with [System.Serializable] will be serialized by Unity, and you can use a BinaryFormatter for runtime serialization.



public class Player {
    public string name;
    public int level;
    int hp;

public class MyScript : MonoBehaviour {
    public Player player;