PropertyDrawer issue.

Hi guys, I’m getting an error when attempting to write a custom PropertyDrawer. This class itself is then exposed to the editor within a MonoBehaviour in an array of that Serializeable class.

So, the class is marked serializable and I do have a property class that is suppose to define the logic for this. However, the result I get is this

The fields appear to bleed out of the defined component space for some reason. This may have something to do with them being an array but I cannot find any information that solves this issue and very little that even mentions it.

Hope someone who has had this issue, and solved it, can enlighten me.

public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
        EditorGUI.PropertyField(position, property.FindPropertyRelative("_SwapTo"));

        float newPropertyHeight = position.top + this.GetPropertyHeight(property.FindPropertyRelative("_ColorReference"), GUIContent.none);

        EditorGUI.PropertyField(new Rect(position.left, newPropertyHeight, position.width, position.height), property.FindPropertyRelative("_ColorReference"));

}

I have solved this problem. You must consider the total height distributed to the custom property, I believe this to be defined by the overrideable height method you’ll find in the base class. Override this to provide adequate height for the property. Then, given the Rect position passed into OnGUI you should evenly distribute the allotted height to the properties. With that you can solve the issue; at least without arrays. I’m about to go test that again in a sec.

Edit: Do not evenly distribute the allotted height in all cases. Not all elements are of the same height or even have their height changed dynamically such as UnityEvents and other collections.

2 Likes