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
  2. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  3. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Thank you - Arrays and lists in the inspector can be reorderable now

Discussion in '2020.2 Beta' started by JoNax97, Jun 3, 2020.

  1. NibbleByte3

    NibbleByte3

    Joined:
    Aug 9, 2017
    Posts:
    81
    Interesting. Didn't try to cache and reuse it. You're right, strangely enough, this fixes the issue. But there is still a bug, the other way should also work, as there are a lot of tools written this way.

    Good catch. :)
     
  2. Novack

    Novack

    Joined:
    Oct 28, 2009
    Posts:
    844
    Found an issue with the new lists on Unity 2020.2.6f1

    If I have this:
    Code (CSharp):
    1. Editor editor = Editor.CreateEditor(someObject);
    2. editor.OnInspectorGUI();
    Lists declared on someObject script are unusable:
    • List inspector wont allow to unfold the lists (you have to force it with ALT+Click).
    • Data set on list elements is not serialized (gets reseted as soon as hitting enter, or focusing a different field).

    They work correctly again if they are marked as NonReorderable. I have this on editor scripts that have been working for the past 4-5 years at least, and got broken by the new lists update.

    Is this known or expected? Any known workarounds?

    Thanks!
     
    moxisgames likes this.
  3. Novack

    Novack

    Joined:
    Oct 28, 2009
    Posts:
    844
    Anyone? @Aras, @LeonhardP, @TomasKucinskas any help appreciated, my toolchain (and thus workflow) is currently partially broken because of this.
     
  4. LeonhardP

    LeonhardP

    Unity Technologies

    Joined:
    Jul 4, 2016
    Posts:
    3,132
    Last edited: Mar 9, 2021
  5. Novack

    Novack

    Joined:
    Oct 28, 2009
    Posts:
    844
    @LeonhardP, thank you! It says its Fixed in 2020.2.7f1, will check that asap and report back.

    The folding issue seems related to the serialization problem, so will review the fix before submitting the new report.
    I'll report back as soon as getting it confirmed.
     
  6. Novack

    Novack

    Joined:
    Oct 28, 2009
    Posts:
    844
    @LeonhardP, in 2020.2.7f1 the serialization issue is fixed, but sadly the folding/unfolding glitch is still present. A bit different, as the parent list fold opens, but each list element wont unfold (except forced with alt+click, but then wont collapse back).

    Will need to make some time to create the issue, as I need to extract the minium example for this, which uses a custom editor. Will do as soon as I can.
     
    LeonhardP and phobos2077 like this.
  7. LeonhardP

    LeonhardP

    Unity Technologies

    Joined:
    Jul 4, 2016
    Posts:
    3,132
    Thank you @Novack, much appreciated! Glad to hear that at least the serialization bug is fixed for you.
     
  8. swedishfisk

    swedishfisk

    Joined:
    Oct 14, 2016
    Posts:
    57
    The Reorderable array is coming along nicely, I just have two gripes left.

    Is this the final look for nested Lists or is it still wip? Because I think it looks much worse than the old one where the lists blended much better.

    Imo it's not worth to have the list header that highlights on mouseover if it doesn't blend at all when nested.



    Also I noticed the expanded state of nested Lists doesn't follow the reordered element when moved. E.g if Element0 has any expanded properties and Element1 does not - it gets flipped when the items are reordered.

    This was also a bug in the top level of list items before, but that has been solved so it's just for nested elements now. Is this known?
     
    Last edited: Mar 16, 2021
    Novack and phobos2077 like this.
  9. jleemans

    jleemans

    Joined:
    Apr 22, 2020
    Posts:
    19
    Hello, the reorderable list are quite a nice additions to Unity, it was very painful to work with list/array before. Thanks
    But There is still a thing that I find misleading. The fact that the name of the list is always bold. When working with prefab and prefab variant, we can have a quick look on what has been modified with field that became bold and the littl blue bar on the side. But my brain and eyes jump fast on lists and beleive it has been changed just because its bold.

    Can you make the list title not bold to stay consistent with the rest of the UI ?
     
  10. swedishfisk

    swedishfisk

    Joined:
    Oct 14, 2016
    Posts:
    57
    Hmm I just noticed a property drawer broke while porting my editor tool to use reorderable lists.

    Since the reorderable list uses some new indentation level, stuff looks way off if we rely on EditorGUI.indentLevel. Is it best to just wing it until indentation looks good or is there something in the api to handle this?

    Edit: It's quite frustrating how much the reorderable lists deviates from the look of everything else in the inspector, a lot of community feedback seems to be ignored in this thread despite being totally valid.
     
    Last edited: Apr 2, 2021
    phobos2077 likes this.
  11. vokh_demetro

    vokh_demetro

    Joined:
    Dec 4, 2019
    Posts:
    7
    I have problem with nested arrays. Nested array is displayed incorrectly.
    Unity 2021.1.2f1. Arrays element overlap enum element.


    array 1.png array.png code .png
     
    Last edited: Apr 14, 2021
  12. ArjenSimons

    ArjenSimons

    Joined:
    Jul 10, 2018
    Posts:
    3
    Have you managed to get it to work in the meantime? For me it also shows as a non reorderable list still in version 2021.1
     
    Nexer8 likes this.
  13. Cascho01

    Cascho01

    Joined:
    Mar 19, 2010
    Posts:
    1,347
    Nested also looks buggy here (Unity2021.1.3f1):

    upload_2021-4-20_10-19-30.png
     
    nomadic and vokh_demetro like this.
  14. BlackHoleTracer

    BlackHoleTracer

    Joined:
    Jan 23, 2014
    Posts:
    7
    Amazing feature!

    Unfortunately it does not work with CustomPropertyDrawer, which uses UI Toolkit (i.e. UIElements, CreatePropertyGUI method).
    The example https://docs.unity3d.com/ScriptReference/PropertyDrawer.html
    will display something like that:
    upload_2021-4-22_0-32-9.png

    With [NonReorderable] attribute:
    upload_2021-4-22_0-31-33.png

    With CustomPropertyDrawer, which uses IMGUI (i.e. OnGUI method) all works good.
    upload_2021-4-22_0-35-24.png

    (Unity 2021.1.3f1)
     

    Attached Files:

  15. vokh_demetro

    vokh_demetro

    Joined:
    Dec 4, 2019
    Posts:
    7
    Unity 2021.1.4 fix this problem. It's good news.
     
  16. BlackHoleTracer

    BlackHoleTracer

    Joined:
    Jan 23, 2014
    Posts:
    7
    Really? I have the same behaviour using Unity 2021.1.4f1.
     
  17. vokh_demetro

    vokh_demetro

    Joined:
    Dec 4, 2019
    Posts:
    7
    unity_fix.png
    I have it displayed as follows.
     
  18. Xarbrough

    Xarbrough

    Joined:
    Dec 11, 2014
    Posts:
    1,188
    Would it be possible to add a way for users to customize additional list drawer properties such as hiding the add/remove buttons? I have a couple of arrays that I force to a specific size via the OnValidate callback, but it looks confusing to designers that the plus and minus buttons still show.

    It doesn't have to be an attribute like the NonReorderable one, it could maybe just be a way for me to use the Editor API to draw my own custom editor or attribute and property drawer but use the official array drawer.
     
    phobos2077 and Nexer8 like this.
  19. Rowlan

    Rowlan

    Joined:
    Aug 4, 2016
    Posts:
    4,200
    Is it possible to show subclasses with this? I created a base class with a boolean and two subclasses, one with a text and the other with a value. But it only shows the property of the base class in the array list.

    Quick example:

    list.png

    Code:

    Code (CSharp):
    1. using System;
    2. using System.Collections.Generic;
    3. using UnityEditor;
    4. using UnityEngine;
    5.  
    6. public class MyListView : MonoBehaviour
    7. {
    8.     #region Classes
    9.  
    10.     [Serializable]
    11.     public class BaseClass
    12.     {
    13.         [SerializeField]
    14.         public bool enabled = true;
    15.     }
    16.  
    17.     [Serializable]
    18.     public class TextClass : BaseClass
    19.     {
    20.         [SerializeField]
    21.         string text = "text";
    22.     }
    23.  
    24.     [Serializable]
    25.     public class NumericClass : BaseClass
    26.     {
    27.         [SerializeField]
    28.         [Range(0f, 1f)]
    29.         float value = 0.5f;
    30.     }
    31.  
    32.     #endregion Classes
    33.  
    34.     #region Data
    35.  
    36.     [SerializeField]
    37.     public List<BaseClass> data = new List<BaseClass>();
    38.  
    39.     #endregion Data
    40.  
    41.     #region Editor
    42.  
    43.     [CustomEditor(typeof(MyListView))]
    44.     [CanEditMultipleObjects]
    45.     public class MyListViewEditor : Editor
    46.     {
    47.         SerializedProperty data;
    48.  
    49.         void OnEnable()
    50.         {
    51.             data = serializedObject.FindProperty("data");
    52.  
    53.             // add data
    54.             MyListView editorTarget = target as MyListView;
    55.  
    56.             if (editorTarget.data.Count == 0)
    57.             {
    58.                 editorTarget.data.Add(new BaseClass());
    59.                 editorTarget.data.Add(new TextClass());
    60.                 editorTarget.data.Add(new NumericClass());
    61.             }
    62.         }
    63.  
    64.         public override void OnInspectorGUI()
    65.         {
    66.             serializedObject.Update();
    67.             EditorGUILayout.PropertyField(data);
    68.             serializedObject.ApplyModifiedProperties();
    69.         }
    70.     }
    71.     #endregion Editor
    72.  
    73. }
     
  20. phobos2077

    phobos2077

    Joined:
    Feb 10, 2018
    Posts:
    350
    Unity doesn't serialize polymorphic objects like that by default.. (it treats your list as a list of BaseClass, regardless of what you assign to elements). You need to use SerializeReferenceAttribute for this. But beware it may be buggy...
     
    Rowlan likes this.
  21. Rowlan

    Rowlan

    Joined:
    Aug 4, 2016
    Posts:
    4,200
    Thank you very much, that seems to work.

    listp.png

    I'll put the working code here in case anyone else needs it:

    Code (CSharp):
    1. using System;
    2. using System.Collections.Generic;
    3. using UnityEditor;
    4. using UnityEngine;
    5.  
    6. [Serializable]
    7. public class MyListViewPolymorphic : MonoBehaviour
    8. {
    9.     #region Classes
    10.  
    11.     [Serializable]
    12.     public class BaseClass
    13.     {
    14.         [SerializeField]
    15.         public bool enabled = true;
    16.     }
    17.  
    18.     [Serializable]
    19.     public class TextClass : BaseClass
    20.     {
    21.         [SerializeField]
    22.         public string text = "text";
    23.     }
    24.  
    25.     [Serializable]
    26.     public class NumericClass : BaseClass
    27.     {
    28.         [SerializeField]
    29.         [Range(0f, 1f)]
    30.         public float value = 0.5f;
    31.     }
    32.  
    33.     #endregion Classes
    34.  
    35.     #region Data
    36.  
    37.     [SerializeReference]
    38.     public List<BaseClass> data = new List<BaseClass>();
    39.  
    40.     public MyListViewPolymorphic()
    41.     {
    42.         data.Add(new BaseClass());
    43.         data.Add(new TextClass());
    44.         data.Add(new NumericClass());
    45.     }
    46.  
    47.     #endregion Data
    48.  
    49.     #region Editor
    50.  
    51.     [CustomEditor(typeof(MyListViewPolymorphic))]
    52.     [CanEditMultipleObjects]
    53.     public class MyListViewEditor : Editor
    54.     {
    55.         SerializedProperty data;
    56.  
    57.         void OnEnable()
    58.         {
    59.             data = serializedObject.FindProperty("data");
    60.  
    61.             // add data
    62.             MyListViewPolymorphic editorTarget = target as MyListViewPolymorphic;
    63.  
    64.             if (editorTarget.data.Count == 0)
    65.             {
    66.                 editorTarget.data.Add(new BaseClass());
    67.                 editorTarget.data.Add(new TextClass());
    68.                 editorTarget.data.Add(new NumericClass());
    69.             }
    70.         }
    71.  
    72.         public override void OnInspectorGUI()
    73.         {
    74.             serializedObject.Update();
    75.             EditorGUILayout.PropertyField(data, true);
    76.             serializedObject.ApplyModifiedProperties();
    77.         }
    78.     }
    79.     #endregion Editor
    80.  
    81. }
     
    phobos2077 likes this.
  22. WookieWookie

    WookieWookie

    Joined:
    Mar 10, 2014
    Posts:
    34
    I've been constructing and animating Unity UI and VFX for 8 years now, using custom inspector tools to complete my workflow. I can tell you that making all things reorderable at all times will present an opportunity for human error, specifically in cases where code is utilizing the index values of items in the array. If an artist can just accidentally reorder the list, those indexes change, and you'll have a bug (although a fairly self-evident one.)

    I'm building a tool today with these concerns in mind, and I came to this thread looking for a way to "lock/unlock" the reorderable functionality. THIS is the solution, to provide access to the reorderable behavior and allow it if you choose according to some logic. For example, I was hoping to find some way to do this:

    Code (CSharp):
    1. [SerializeField] private bool editable = false;
    2.  
    3. listName.reorderable = editable;
    OR

    Code (CSharp):
    1. listName.SetEditable(editable);
     
    Last edited: Sep 22, 2021
    nomadic and Novack like this.
  23. Mashimaro7

    Mashimaro7

    Joined:
    Apr 10, 2020
    Posts:
    727
    It's kinda weird that you have to click on the specific point of the element to reorder it not just click on the element... I thought it was gone and you weren't able to reorder anymore, so I went to post saying "Has this feature been removed?" lol
     
  24. Novack

    Novack

    Joined:
    Oct 28, 2009
    Posts:
    844
    Hey @LeonhardP, looks like a known issue was reintroduced in Unity 2022.1.0f1.
    Same as last time I mentioned it, If I have this:
    Code (CSharp):
    1. Editor editor = Editor.CreateEditor(someObject);
    2. editor.OnInspectorGUI();
    Lists declared on "someObject" script are unusable: data input (on list elements of any type), is not serialized correctly, and you can see how it gets reseted as soon as hitting enter, or focusing a different field.

    I left a comment on the issue ticket you mentioned the last time, but it now is marked as fixed, so not sure if a new one should be created.
     
  25. LeonhardP

    LeonhardP

    Unity Technologies

    Joined:
    Jul 4, 2016
    Posts:
    3,132
    Hi @Novack, could you please submit a new bug report for this with the information you shared here? That will ensure that QA will look into it.
     
  26. Novack

    Novack

    Joined:
    Oct 28, 2009
    Posts:
    844
    Thanks @LeonhardP, and done: report id is IN-2510. Aren't these reports public anymore? I had to create an account to access it.
     
  27. Thanitsak

    Thanitsak

    Joined:
    Jan 4, 2016
    Posts:
    116
    Same here my Progresion file is really broken. Any work around for this or any solution? Unity 2021.3.3f1 (Silicon)
     

    Attached Files:

  28. Novack

    Novack

    Joined:
    Oct 28, 2009
    Posts:
    844
    @Thanitsak my report was for a different one, where you cannot change data on the lists if you're using a custom editor.
    The one you show happened on all editors, including Unity standard inspector, and is fixed on the latest Unity 2022, so I would try the latest patch release for Unity 2021, which is likely to have fixed it.
     
  29. Thanitsak

    Thanitsak

    Joined:
    Jan 4, 2016
    Posts:
    116
    @Novack Ah I see haha anyways after update to Unity 2022.1.1f1 (Silicon) fix the problem, thanks
     
    Novack likes this.
  30. swedishfisk

    swedishfisk

    Joined:
    Oct 14, 2016
    Posts:
    57
    Is there a ticket for this issue?

    I just upgraded to LTS 2021.3.3 and was very surprised all my lists were so broken when they were working perfectly in 2020.
     
  31. Thanitsak

    Thanitsak

    Joined:
    Jan 4, 2016
    Posts:
    116
    Not sure about that either if anyone has did, yea same was very surpricsed! But I would just update to newer version to 2022 to fix this if still no solution for 2021. Anyways I didn't make one yet busy with making game menu.
     
  32. SharpAccent

    SharpAccent

    Joined:
    Jul 19, 2018
    Posts:
    39
    2021.3.4f1 Reorderable list still broken, to recreate you can just make a new project and add an array

    upload_2022-6-14_18-9-45.png
     
  33. Feelnside

    Feelnside

    Joined:
    Sep 30, 2016
    Posts:
    83
    Good to know Unity 2021.3.2.f1 works without the issue (Unity 2021.3.3.f1 and Unity 2021.3.4.f1 have the issue)
     

    Attached Files:

  34. Novack

    Novack

    Joined:
    Oct 28, 2009
    Posts:
    844
  35. Novack

    Novack

    Joined:
    Oct 28, 2009
    Posts:
    844
    Oh lord. A year later, the issue was closed as "wont fix" with an obscure note that reads:

    "The described scenario works when using the SerializedObject instead of the target as it is advised my Unity documentation."

    What in the world is he talking about?

    @LeonhardP any chances of giving a hand here? Is not even clear what is saying, and how relates to an issue that doesnt involve custom drawing, and takes only a few lines to repro.

    This a whole wasted year, after a regression of the same issue for the second time, to only stomp into an incredibly dismissive person on the other side, that wont care to understand an issue that takes 30 lines to test. I swear Unity bug fixing is the worst I've seen in a long while.

    Take this, again:
    Code (CSharp):
    1. using System;
    2. using System.Collections.Generic;
    3. using UnityEditor;
    4. using UnityEngine;
    5.  
    6. namespace ReorderableListTest
    7. {
    8.     public class TestWindow : EditorWindow
    9.     {
    10.         [MenuItem("Tools/Test", priority = 5000)]
    11.         static void Init()
    12.         {
    13.             var window = EditorWindow.GetWindow<TestWindow>();
    14.             window.titleContent.text = "Test";
    15.             window.Show();
    16.         }
    17.  
    18.         private void OnGUI()
    19.         {
    20.             Editor editor = Editor.CreateEditor(Selection.activeObject);
    21.             editor.OnInspectorGUI();
    22.         }
    23.     }
    24.  
    25.     [CreateAssetMenu(fileName = "TestSO", menuName = "Create TestSO Asset", order = 1)]
    26.     public class TestSO: ScriptableObject
    27.     {
    28.         [Serializable]
    29.         public class TestClass
    30.         {
    31.             public string testString;
    32.             public int testInt;
    33.         }
    34.  
    35.         public List<TestClass> testClasses;
    36.     }
    37. }
    ...
    Kindergarden guide:
    1. Add this script to Unity.
    2. Create the TestSO ScriptableObject asset.
    3. Go to the standard inspector, add a few elements to the list.
    4. Open the Test window and try to edit the list element fields
    ... and the results are pretty much self explanatory.

    upload_2023-5-26_11-12-10.png

    At this time, Im on Unity 2022.2.12.
    Edit: Notes on timing and prioritization... The list drawer is pretty much core to the Unity Editor. Can you imagine not having a functional list drawer in your project toolset? Can you imagine having the same issue regressed several times along time, and having to wait for a year each time? Who does the triage on this issues? Shouldnt regressions take critical priority? So many questions.
     
    Last edited: Jun 15, 2023
  36. Novack

    Novack

    Joined:
    Oct 28, 2009
    Posts:
    844
    Anyone...?

    QA is mistakenly closing a very important issue. Nobody at Unity will bother to do anything?

    Is the "resolution note" in the report supossed to be for us, or for the internal Reorderable List devs? Is unclear, and ultimately useless for us (have some respect for the people that reported the bug?) as keeps us in the dark for an issue that is a regression with a year in the wild.
     
  37. TomasKucinskas

    TomasKucinskas

    Unity Technologies

    Joined:
    Dec 20, 2017
    Posts:
    60
    @Novack My advice would be to not recreate your editor every frame. Reorderable list picky for that particular scenario and since we're moving towards UI Toolkit solutions, we are reluctant to do major revisions to the old control at this point to not possibly break other scenarios.

    I've seen several of these cases already and all of them could be solved in a number of ways:
    • Creating editor as UI Toolkit object via InspectorElement
    • Using Non-Reorderable attribute
    • Using a persistent editor instance (that's the solution I suggested in the beginning of the message)
    I hope this helps you fix the problem.
     
  38. Novack

    Novack

    Joined:
    Oct 28, 2009
    Posts:
    844
    @TomasKucinskas, oh my, that actually fixed it! Very, very greateful to you.

    I moved the editor creation to an event invoked on selection change. When you think about it, makes absolute sense, but never considered this as a potential solution, because I knew the root cause was this known bug (a regression now) on the reorderable list drawer.

    By god, why took so hard to have an answer that made sense, is beyond me. But thank you for jumping in and giving a hand.
     
    TomasKucinskas likes this.
  39. dizzymediainc

    dizzymediainc

    Joined:
    Apr 6, 2014
    Posts:
    426
    Probably redundant at this point but i found in Unity 2021.3.2 that my custom editor window lists were no longer working even though they worked fine in Unity 2020.3.7 (i.e any type of list, could not drag / drop, manually assign, etc.)

    The issue was

    Code (csharp):
    1.  
    2.             if(EditorGUI.EndChangeCheck()){
    3.  
    4.                 soTar.ApplyModifiedProperties();
    5.  
    6.             }//EndChangeCheck
    7.  
    use at the end of OnGUI, removing this fixed all lists that were previously working. Backwards testing in Unity 2020.3.7, lists still work when removing if(EditorGUI.EndChangeCheck()){

    Not sure exactly what the cause of this is but i assume it's something to do with Unity 2021 reordable lists introduction.
     
  40. dizzymediainc

    dizzymediainc

    Joined:
    Apr 6, 2014
    Posts:
    426
    It's also fair to note that while lists worked with the above mentioned fix, there were still some issues
    (i.e manual assign did not work, etc.)

    The only way to fully fix the list was as Xarbrough mentioned in my quote link above, you have to serialize the object on enable and then place serializedObject.Update() at the beginning of OnGUI.

    This is the only fix i have found that actually completely fixes list usage and allows for drag / drop, manual assign, etc. usage without any issues.
     
  41. bourriquet

    bourriquet

    Joined:
    Jul 17, 2012
    Posts:
    181
    I have a custom list attribute drawer that used to trick the old array display by drawing the whole collection in the 1st element, then hide other elements by setting their height to zero.
    This doesn't work anymore with the default reorderable layout, as other elements are forced to show, with their reorder handles, even if their height is zero.
    Adding [NonReorderable] along with my custom attribute partially fixes it, but:
    1. It's a plugin, so I would like to set the collection NonReorderable by code, rather than ask every user to add [NonReorderable] everytime they use my attribute.
      So is there a way to set NonReorderable by editor code?
    2. There's still some extra layout: the surrounding box and the + & - buttons
      Is there a way to remove those too?
    Unity 2019:
    upload_2023-10-26_17-9-30.png

    Unity 2021:
    upload_2023-10-26_17-10-28.png