- Home /
EditorGUI.PrefixLabel returns a rect that doesn't line up with other content when a custom property drawer is used in an array.
I am creating a custom property drawer for a ScriptableObject. I have the following code to draw a prefix label and then the field.
position = EditorGUI.PrefixLabel(position, GUIUtility.GetControlID(FocusType.Passive), label);
EditorGUI.PropertyField(position, property, GUIContent.none);
I would have thought that this would display just like any other field looks by default. However, when it is within an array, the content after the label is too far to the right. See in the image below how the item field (driven by my custom property drawer) is not lined up with the Weight, which has no custom property drawer.
What should I do different to have the field line up with the others when in an array?
Answer by dan_wipf · Feb 02, 2019 at 06:46 AM
what about if you do new GuiContent(“”)
Thanks @dan_wipf . That lead me to a workaround in which I ditched EditorGUI.PrefixLabel and used the builtin label in the PropertyField.
EditorGUI.PropertyField(position, property, label);
that would have been the second advise i’d have given you!
Answer by br0br0br0 · Dec 01, 2020 at 08:43 AM
Adding EditorGUI.indentLevel--; before the EditorGUI.PropertyField( worked for me.
Your answer
Follow this Question
Related Questions
Can you use Editor.DrawDefaultInspector() inside a property drawer? 1 Answer
PropertyDrawer.fieldInfo returns array instead of eleme 2 Answers
How to sort a built-in array in the inspector? 2 Answers
How do PropertyAttribute instances work in an array of structs? 1 Answer
How do I assign 3 variables to every GameObject in the array "enemy"? 2 Answers