- Home /
Inheritance and Serialization
hi guys, is there a reason that this:
[System.Serializable]
public class ExampleClass : ScriptableObject
{
[SerializeField]
public List<ParentClass> exampleClasses = new List<ParentClass>()
{
new ParentClass(),
new ChildClass()
};
}
[System.Serializable]
public class ParentClass
{
}
[System.Serializable]
public class ChildClass : ParentClass
{
}
would serialize to be a list with two ParentClass elements instead of one ParentClass and one ChildClass. Is it because of the [serializefield] attribute before the list? if so how can I serialize this whilst still respecting the classes I want?
Answer by Adam-Mechtley · Dec 06, 2016 at 03:46 PM
Unity does not support polymorphic serialization, so every list element will just serialize as a ParentClass. You might find my response to this question helpful.
Your answer
![](https://koobas.hobune.stream/wayback/20220612102151im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Serialization of inherited classes, could this work? 0 Answers
Calling a derived class (Serialized in a Scriptable Object) returns the super class. 1 Answer
Saving class data without having lots of references? 1 Answer
unity doesn't recognize the derived class 3 Answers
Serializing invetory items data and InvalidOperationException exception 0 Answers