In this lesson, you will learn how to create clean, readable interfaces for complex nested data structures using PropertyDrawers so you can edit deep object hierarchies directly in the Inspector.
The Problem with Deep Nesting
When you have a class inside a class—like an Inventory containing a List of ItemData—Unity’s default Inspector often produces a cluttered, unmanageable mess. The "default" view forces you to click through endless levels of foldouts, making it easy to lose context. To keep your workflow efficient, we use PropertyDrawers.
Introducing PropertyDrawers
A PropertyDrawer allows you to define exactly how a specific class should be rendered in the Inspector. Instead of letting Unity "guess" how to show your data, you tell it: "When you see this type, draw it like this."
To use this, you must mark your class with the [System.Serializable] attribute and create a new script inside an Editor folder. Here is a basic example of how you might start customizing the layout:
[CustomPropertyDrawer(typeof(InventoryItem))]
public class InventoryItemDrawer : PropertyDrawer
{
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
EditorGUI.BeginProperty(position, label, property);
// Use SerializedProperty to access nested fields
SerializedProperty name = property.FindPropertyRelative("itemName");
SerializedProperty amount = property.FindPropertyRelative("quantity");
// Define positions for our fields
Rect nameRect = new Rect(position.x, position.y, 100, EditorGUIUtility.singleLineHeight);
Rect amountRect = new Rect(position.x + 105, position.y, 50, EditorGUIUtility.singleLineHeight);
// Draw them side-by-side instead of in a long vertical list
EditorGUI.PropertyField(nameRect, name, GUIContent.none);
EditorGUI.PropertyField(amountRect, amount, GUIContent.none);
EditorGUI.EndProperty();
}
}
Why This Matters
By drawing your data horizontally or grouping related properties together, you reduce the "scroll distance" in your Inspector. This makes your custom tools feel like native Unity features. When your data is easy to read, you spend less time hunting for variables and more time balancing your game values.
Key Takeaway: PropertyDrawers transform cluttered nested objects into intuitive, custom-built interfaces, significantly improving your workflow efficiency in the Inspector.