Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. The 2023.1 beta is now available for testing. To find out what's new, have a look at our 2023.1 feature highlights.
    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
    SugoiDev, oli-2019, Hyp-X and 2 others like this.