- Home /
First item in inspector list is incorrect height
I created a custom property drawer like so:
using UnityEditor;
using UnityEngine;
[CustomPropertyDrawer(typeof(DialogLine))]
public class DialogLinePropertyDrawer : PropertyDrawer
{
private const int Padding = 5;
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
// Calculate reusable values
var start = position.x;
var top = position.y;
var half = position.width / 2.0f;
var line = EditorGUIUtility.singleLineHeight;
// Draw fields - pass GUIContent.none to each so they are drawn without labels
var speakerRect = new Rect(start, top, half, line);
EditorGUI.PropertyField(speakerRect, property.FindPropertyRelative("speaker"), GUIContent.none);
var clipRect = new Rect(start + half, top, half, line);
EditorGUI.PropertyField(clipRect, property.FindPropertyRelative("clip"), GUIContent.none);
var emotionRect = new Rect(start, top + line + Padding, half, line);
EditorGUI.PropertyField(emotionRect, property.FindPropertyRelative("emotion"), GUIContent.none);
var positionRect = new Rect(start + half, top + line + Padding, half, line);
EditorGUI.PropertyField(positionRect, property.FindPropertyRelative("position"), GUIContent.none);
var textRect = new Rect(start, top + (line + Padding) * 2, position.width, line * 2);
EditorGUI.PropertyField(textRect, property.FindPropertyRelative("text"), GUIContent.none);
}
public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
{
return EditorGUIUtility.singleLineHeight * 4 + Padding * 4;
}
}
It works as expected, except the first item in a list of that type always displays with the incorrect height. (See the image below and how the first item renders partially behind the second one.)
Is there something wrong with my code or a workaround I can use to fix this?
Unfortunately, I don't have an answer, but want to let you know that I suffer from the exact same bug on Unity 2022.1.0b16.3019 (Linux). The first entry simply always has the wrong height and renders partially behind the second one. Judging by the 160+ followers of this question I guess we are not alone...
Followers get added automatically by the forum based on subscriptions to tags. If you add "C#" as tag you'll have 500+ followers on your question. This sadly means nothing at all.
Given that you both encounter this issue perhaps you should open an official bug report on unity.
Looks like this is a Unity bug: https://issuetracker.unity3d.com/issues/first-array-element-expansion-is-broken-for-arrays-that-use-custom-property-drawers
Supposedly it's been fixed, but the problem is still there for me.
Your answer
Follow this Question
Related Questions
(Solution) - Can't use GUILayout stuff in PropertyDrawer.OnGUI? 2 Answers
CustomPropertyDrawer of a Generic List. 1 Answer
Unity won't let me override the default way of drawing an array/list? 2 Answers
What does "flagsCount >= mask.m_Count" mean? 0 Answers
OnGUI mystically stopped rendering buttons and text. 1 Answer