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

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    5,242
    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
unityunity