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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

(Case 1188478) List of generic type not serialized

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

  1. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    6,471
    Unity 2020.1 comes with "Support for serializing fields of generic types directly"
    https://forum.unity.com/threads/preview-of-2020-1-features.742052/

    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):
    1.  
    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;
    Reproduce
    • Open attached project
    • Open SampleScene.unity
    • Select "Test" game object in Hierarchy

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

    Expected
    "m_ListOfOptionalFloat" should be serialized too.

    EDIT: Link to issue tracker:
    https://issuetracker.unity3d.com/is...en-tagging-them-with-serializefield-attribute
     

    Attached Files:

    Last edited: Oct 18, 2019