- Home /
Empty space at the top of a custom property drawer layout?
I'm talking about the empty space it leaves here above the "Text" label, which seems to be caused by the CustomPropertyDrawer for the localized text class:
http://i.imgur.com/M0qjhdU.png
Here I put a (absolute positioned) label right at the position passed to the CustomPropertyDrawer OnGUI method:
http://i.imgur.com/SDl6CVa.png
Is there a reason why the GUILayout methods skip a line?
Answer by Fissioner · Mar 21, 2021 at 08:35 PM
Here we are 5 years later.
I was facing the same problem and here is a hacky, yet simple and effective way to fix this issue:
public override float GetPropertyHeight(SerializedProperty property, GUIContent label) { return 0; }
Add this override to the PropertyDrawer class and extra spaces will be gone (if you face any problems, do let me know)
or, if you want to be extra elegant:
public override float GetPropertyHeight(SerializedProperty property, GUIContent label) => 0;
Answer by Adam-Mechtley · Oct 25, 2016 at 09:01 AM
Hi! Looks like the problem is not your label field, but the text input field after it. For some reason it is not drawing the full height of the space you have allocated for it. Not sure if it's affecting this case but, you should not use EditorGUILayout inside of a PropertyDrawer. Just use the corresponding EditorGUI methods and manage the rectangles yourself. For example:
EditorGUI.BeginProperty(position, label, property);
Rect labelRect = position;
labelRect.height = EditorGUIUtility.singleLineHeight;
EditorGUI.PrefixLabel(labelRect, label);
position.y += labelRect.height + EditorGUIUtility.standardVerticalSpacing;
position.height -= EditorGUIUtility.standardVerticalSpacing + labelRect.height;
// do some text input control using position rect
EditorGUI.EndProperty();
That said, is there any reason you cannot use the built-in TextAreaAttribute for this case?
The LocalizedText class can have multiple text entries for a varying amount of languages, and has to give a warning when the text becomes too long. Hence I used a custom property drawer for it.
Your answer
Follow this Question
Related Questions
What is a GUILayoutOption[] 3 Answers
Custom Editor Search bar 2 Answers
Drawing Editor Inspector GUI based on selected/current prefab (CustomPropertyDrawer) 2 Answers
Unity editor GUI, how to prevent "passthrough"/"clickthrough" etc? 0 Answers
Null reference exceptions when using a Custom Editor 0 Answers