Can Unity serialize generic classes?

Can Unity serialize generic classes?

Scripting: The serializer can now serialize fields of generic types (e.g. MyClass someField) directly; it is no longer necessary to derive a concrete subclass from a generic type in order to serialize it.

What is using UnityEngine?

“using UnityEngine;” Basically, this tells $$anonymous$$onoDevelop that you are using Unity’s version of C#. you aren’t using Unity’s version of C#, you are using the standard C#. That lines means you are importing the UnityEngine namespace.

Can Unity serialize interfaces?

In contract to old [SerializeField], this will allow us to serialize interfaces, abstract classes, and polymorphic data. There are also lesser, but still comfortable improvements (like having fields serialized to null in the inspector).

Can a generic type be serialized in a script?

Scripting: The serializer can now serialize fields of generic types (e.g. MyClass someField) directly; it is no longer necessary to derive a concrete subclass from a generic type in order to serialize it. I’d argue this beauty needs its own entry in the 2020.1 features list!

When does serialization of a generic class crash?

It crashes if any generic class is directly serialized with SerializeReference with compute_class_bitmap: Invalid type 13 for field Container`1 [T]:Value LeonhardP and Peter77 like this. I took a quick look at it recently and only got an editor crash when executing “a = new D ();”.

Is there a way to serialize generic fields in Unity?

To find out what’s new, have a look at our 2021.2 beta blog post. Scripting: The serializer can now serialize fields of generic types (e.g. MyClass someField) directly; it is no longer necessary to derive a concrete subclass from a generic type in order to serialize it.

Is it possible to serialize a bool in Unity?

Hope it’s juste an alpha bug and that it will be supported in the future. This looks nice, tested a few cases. This will probably enable Unity to also mark the UnityEvent classes as serializable and make them non abstract; so that we could serialize UnityEvent directly without creating a subclass first.