- Home /
Do PropertyDrawers support inheritance?
Playing around with custom editors led me to use inheritence a bit, and it worked fine:
The parent editor class:
[CustomEditor(typeof(Parent))]
public class ParentEditor: UnityEditor.Editor
{
public override void OnInspectorGUI()
{
// Code here
}
}
The child editor class:
[CustomEditor(typeof(Child))]
public class ChildEditor: ParentEditor
{
public override void OnInspectorGUI()
{
base.OnInspectorGUI();
// New code here
}
}
But the same isn't possible with Property Drawers. The child's OnGUI method is simply ignored and only the parent's OnGUI method is being called.
Am I missing something?
Answer by Matheuz · Mar 13, 2015 at 12:35 AM
So I found out that all the PropertyDrawers that inherit from a drawer that has the useForChildren parameter set true in the attribute
[CustomPropertyDrawer(typeof(Ingredient), true)]
It must have the parameter parameter set as true also, otherwise it won't work.
From the documentation:
useForChildren: If true, the drawer will be used for any children of the specified class unless they define their own drawer.
Your answer
Follow this Question
Related Questions
Custom Editor/Custom Property Drawer combo, breaks Enable button 1 Answer
An OS design issue: File types associated with their appropriate programs 1 Answer
Marking property as dirty in property drawer after changing its objectReferenceValue 1 Answer
CustomPropertyDrawer undoable properties 1 Answer
FindPropertyRelative for inherited classes isn't working 1 Answer