- Home /
Can you use Editor.DrawDefaultInspector() inside a property drawer?
Inside a custom editor, I can draw the inspector for any scriptable object with the following code:
CreateCachedEditor(myScriptableObject, null, ref cachedEditor);
cachedEditor.DrawDefaultInspector();
I would like to know if it is possible to do the same thing inside a property drawer. I have a property drawer for a scriptable object, and I want to draw the object's inspector as part of the property drawer. If I try to add the above code to the property drawer, I of course get errors (ArgumentException: Getting control 12's position in a group with only 12 controls when doing mouseDown). This code is not run during a layout event according to debug logs.
Answer by MartinIsla · Feb 05, 2019 at 04:57 AM
Not really sure, but let's figure out together.
In the PropertyDrawer, you override OnInspectorGUI(...) {}, right? Inside OnInspectorGUI, you can call DrawDefaultInspector();.
The problem with property drawers is they're super bitchy about using Layout. You actually have to keep track of their width and height manually. That's not cool, bro.
I think you're getting PropertyDrawers and custom Editors confused (because no, you don't override OnInspectorGUI in the former)
Holy moly, you’re damn right. In my defense, it was pretty late. That still looks like you’re using GUILayout and you shouldn’t use layout with property drawers.
Thanks for the downvote!
You’re drawing an inspector in a property drawer. Not cool. Why don’t you just EditorGUI.PropertyField?