[SOLVED] ScriptableObject generic list makes all derived instances to base type when serializing

I’m trying to make a stat system library to use in as many games as possible in the future, but unity’s serialization got in the way.


Knowing how awful is the serialization in unity and that derived instances get transformed to base type during serialization, I decided to make the base class derive from ScriptableObject, but it does not work.
My code was becoming a bit messy at this point so I decided to make a much simpler test version from scratch, by the book, as explained here:

https://forum.unity.com/threads/serialization-best-practices-megapost.155352/

But that didn’t work either.


The base class:
139637-baseclass.png
The derived class:


If I press Play and add a new derived instance to the list, it is recognized properly until I press Play again, when the derived instance gets moved to base type.

I tried a lot of things, but none seem to work so thank you for trying to help me.

OK I figured it out. I was not creating assets out of the 2 classes. ScriptableObjects as assets can’t reference non asset / prefab instances apparently, so the data of my list of BaseClass got lost.

Conclusion: it’s not enough to make a ScriptableObject wrapper for ScriptableObject fields that you make an asset out of, but you need to make assets out of the fields too.