- Home /
Question by
JonYoung · Jul 07, 2014 at 10:10 AM ·
editorinspectorserializationserializefieldunity 4.5
Why can't a MonoBehaviour subtype with generic arguments be serialized in a list since Unity 4.5?
Previous to unity 4.5 we could have serialized list fields of a type with generic arguments provided that the type derived from MonoBehaviour. This was a powerful abstraction technique which allowed us to avoid having to write concrete classes for every possible generic argument.
No one seems to be aware of this on the web and I am wondering what has happened. Is it deprecated functionality? If so does anyone know why and how to work around it without writing countless concrete classes? I have already sent a bug report in case it is a bug.
Here is an example of what I mean:
public class GenericMonoBehaviourContainer : MonoBehaviour
{
//this turns up in the inspector previous to Unity 4.5
[SerializeField] private List<GenericMonoBehaviour<GameObject>> _behaviour;
//this will turn up in the inspector regardless
[SerializeField] private List<NonGenericMonoBehaviour> _concreteBehaviour;
}
public class GenericMonoBehaviour<T> : MonoBehaviour
{
}
public class NonGenericMonoBehaviour : GenericMonoBehaviour<GameObject>
{
}
Edit: I have just found out that previous to Unity 3.5 the serialization only works if the field is a list so I have updated the code example and question.
Comment