1
\$\begingroup\$

So I'm new to using Serialaiziblewtfever(I just cannot remember the correct spelling). In the Unity editor it works fine if I have something like:

[System.Seriliabizblewtfever]
Public class BaseClass{
    public ChildClass showvariables;
}
[System.serializable]
Public class ChildClass{
    public float nipz;
}

With that I can see the variables "nipz" in the inspector when I click the drop-down arrow. However, I want ChildClass to be an actual child class so I can manipulate variables inherited from the parent. So if I change it to:

Public class ChildClass:BaseClass

It stops working. It doesn't matter what class the "BaseClass" is. In the inspector it shows me "showvariables", but then has the field like how you can drag objects, transforms, etc, but no drop down list of any variables. Is there something I'm missing?

\$\endgroup\$

1 Answer 1

1
\$\begingroup\$

Unity's serialization system doesn't support inheritance for custom serializable class. In order to correctly serialize fields of a polymorphic type it must be derived from MonoBehaviour or ScriptableObject.

For your example BaseClass should extend MonoBehaviour to make it work.

In addition, custom serialized class references won't be resolved. This means that if 2 class A have a field referencing the same instance of a class B, the 2 field will be serialized separately and so you'll end up with 2 instance of class B one assigned to each field of the class A.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .