Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice

Cannot Serialize lists or arrays of generic types

Discussion in '2020.1 Beta' started by jasonatkaruna, Nov 16, 2019.

  1. jasonatkaruna

    jasonatkaruna

    Joined:
    Feb 26, 2019
    Posts:
    64
    Not sure if this is a known issue, or if it's intended, but as of now, you cannot serialize lists or arrays of generic types.

    The following won't serialize:

    Code (CSharp):
    1. [Serializable]
    2. public class Wrapper<T>
    3. {
    4.     public T wrappedValue;
    5. }
    6.  
    7. public class MyMonoBehaviour : MonoBehaviour
    8. {
    9.     public Wrapper<int>[] wrappers; // this won't serialize
    10.     public Wrapper<int> singleWrapper; // this serializes fine
    11.     public int[] ints; // this serializes fine
    12. }