- Home /
Expanding a custom property drawer of a list item forces further items in the list to disappear.
(I posted this question in the forums, but I think it doesn't have such visibility as here).
I made a custom Drawer of a class (Item). And another class containing a list of those items (ItemList).
The inspector show this:
But when expanding some element, the others get faded out:
This is a minimal reproducible example (deleting the CustomPropertyDrawer makes it work though, but deleting the Drawer is not an option in my production code).
using UnityEngine; #if UNITY_EDITOR using UnityEditor; #endif public class ItemList : MonoBehaviour { public Item[] ListOfItems; } [System.Serializable] public class Item { public string _Name; } #if UNITY_EDITOR [CustomPropertyDrawer(typeof(Item))] public class ItemDrawer : PropertyDrawer { public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { EditorGUI.BeginProperty(position, label, property); EditorGUI.PropertyField(position, property, label, true); EditorGUI.EndProperty(); } public override float GetPropertyHeight(SerializedProperty property, GUIContent label) { float height = EditorGUI.GetPropertyHeight(property, label, true); return height; } } #endif
Thanks for considering my request.
Answer by awsapps · Aug 16, 2021 at 07:02 PM
Found it, within an empty project, it works in 2020.3 but not in 2021.1
Answer by Bunny83 · Aug 16, 2021 at 03:07 PM
Uhm, I just copied your code varbatim to my test project and I get:
So you either have some dodgy serialized data which may mess up your property (though in such a case I would expect to see some errors or warnings in the console), or the code you've posted is not the code you're using. Are you sure there are no compiler errors at all in your whole project?
ps: It seems really weird to have an int variable called "name".
Thanks for your fast reply. Indeed, the code wasn't the latest. It's updated now. The code you just use doesn't work for me either, so I suspect is a problem about the version/platform of Unity. I'm currently using Linux Fosa + Unity 2021.1.11f1.
Your answer
Follow this Question
Related Questions
Custom editor script for folders? 1 Answer
how to display variable of function in inspector 1 Answer
Handles not displaying 1 Answer