List of Custom Class in Scriptableobject Loses Data On Play (Unable To Cast Parent To Child)
Hello,
I have a custom class named GUIElement, and a list of it in my scriptableobject class.
GUIElement has many child classes.
class Child1 : GUIElement .. .. class Child2 : GUIElement .. ..
And so on. I use the something like the following when adding new objects to the list.
List list;
list.Add(new Child1());
.. ..
Then I try to access it using the following and get InvalidCastException.
Child1 object = (Child)list[0];
I know that from many ChildX classes this one was a Child1, because I have a type variable in the parent class which I set in the child's constructor so that I know which class it is when I am casting back.
It works, but when I hit play or close/reopen Unity, the console says that it cannot cast it back. It still keeps the data though, and it knows the type I set before. Just cannot cast while it can before.
What is the problem?
Thanks
Your answer
