Custom Serialization of Objects

So, I’m trying to serialize my Finite-State-Machine System I’ve built, but I’m having problems, because unity doesn’t support polymorphism serialization.
For instance, my State class has a
“protected IStateAction action;” declared, and that spot is to be used by a class inheriting that interface.

Okay, I know Unity doesn’t support polymorphism, I get that, but how am I supposed to do a custom serialization?

I have my serializer from our studio’s old engine (which BTW can serialize anything you throw at it, which was work of one week for me, I really don’t understand what is going on with the serialization on Unity), I have all it’s classes but there seems to be no event when there’s a scene save. I’ve thought about going around and serializing using my system to a byte, letting unity serialize that and then converting it to a MemoryStream, but I don’t have access to any event that I can use to know it’s time to serialize.

I think what you’re looking for is the EditorApplication.playmodeStateChanged. I’ve given an example of how to use it in this question

An example of such custom serialization system is VFW, it serializes generics, polymorphic types, auto-properties, static fields, readonly fields, etc. The key things are ISerializationCallbackReceiver and a good custom serializer. Since you’re saying you already have a good serializer, then you just need to connect the dots and use surrogates to hack the persistence of Unity objects as seen here (old answer, but the basic idea is the same…)