Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice
  2. Enter the 2020.2 Beta Sweepstakes for a chance to win an Oculus Quest 2.
    Dismiss Notice

(Case 1188478) List of generic type not serialized

Discussion in '2020.1 Beta' started by Peter77, Oct 2, 2019.

  1. Peter77


    QA Jesus

    Jun 12, 2013
    Unity 2020.1 comes with "Support for serializing fields of generic types directly"

    Considering the following generic type:

    Code (CSharp):
    1. [System.Serializable]
    2. public struct OptionalValue<T>
    3. {
    4.     [SerializeField] T m_Value;
    5.     ...
    Using it as a member of a MonoBehaviour, correctly exposes it to the Inspector:
    Code (CSharp):
    2. public class NewBehaviourScript : MonoBehaviour
    3. {
    4.     [SerializeField]
    5.     OptionalValue<float> m_OptionalFloat;
    However, using it as a List<> does not expose it to the Inspector:
    Code (CSharp):
    1. public class NewBehaviourScript : MonoBehaviour
    2. {
    3.     [SerializeField]
    4.     List<OptionalValue<float>> m_ListOfOptionalFloat;
    • Open attached project
    • Open SampleScene.unity
    • Select "Test" game object in Hierarchy

    Observe in the Inspector it displays "m_OptionalFloat", but does not display "m_ListOfOptionalFloat"

    "m_ListOfOptionalFloat" should be serialized too.

    EDIT: Link to issue tracker:

    Attached Files:

    Last edited: Oct 18, 2019