[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: 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.
Answer by PridesFall08 · Jun 08, 2019 at 09:08 AM
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.
Your answer
Follow this Question
Related Questions
Serializable Class On ScriptableObject Null when loaded from AssetBundle 2 Answers
Serialize a list of class containing ScriptableObject assets 0 Answers
How the heck do I save this info for my characters? [Serialization Usage Question] 1 Answer
[Solved] Custom editor resets after Play? 3 Answers
Unity3D ScriptableObject with UnityEvent not saving event parameter 0 Answers