I have a custom PropertyDrawer that I am using for a custom Velocity-struct.
I’m using this struct in a ScriptableObject, and when I create a PropertyField in the Editor for this ScriptableObject the PropertyDrawer works just fine.
However: I’m also nesting the Inspector for this ScriptableObject inside of the Editor for another ScriptableObject. Inside of that editor, the PropertyField is not rendered at all. The nested Inspector is drawed by calling CreateEditor(asset).CreateInspectorGUI()
Above you can see the difference between the Nested (left) and Normal (right) inspectors.
If I check the layout through the UIToolkit Debugger, I can see that the Propertyfield is completely empty.
Above: Nested Inspector. Below: Regular Inspector
I’m able to work around the issue by manually calling new VelocityPropertyDrawer().CreatePropertyGUI() instead of using a PropertyField,
but this seems like a bug in UITookit itself.
in your case, note that the automatic Bind() call in the Inspector will always Bind the entire inspector GUI to the same (currently selected) GameObject. since you add a nested Inspector for a Object, all of that UI will still try to Bind() to the active GO, so you need to call Bind(nestedObject) explicitly, after the main Bind(), on your nested Object Inspector root to rebind to the correct Object.
you should do this after the main Bind() by using the GeometryChangeEvent (registered once on your root inspector element and then unregistered)
@axeldubillet
“all of that UI will still try to Bind() to the active GO”
Why would it try to Bind() to an active GO if I’m creating it by calling CreateEditor(childObject).CreateInspectorGUI()? Shouldn’t that just directly call the CreateInspectorGUI of my Editor-Script?
Furthermore: My nested ScriptableObject is rendering just fine. It’s the PropertyDrawer inside of that object that isn’t showing up. If I draw that with ‘new PropertyField(childProp)’ it doesn’t work, but if I do that with ‘new MyPropertyDrawer().CreatePropertyGUI(childProp)’ it works fine.
If I open the Editor for the nested ScriptableObject, it also renders fine.
It seems like Unity just isn’t loading the MyPropertyDrawer? (As in it doesn’t know which PropertyDrawer to render when using ‘new PropertyField()’)
Hmm… Somehow adding an additional .BindProperty() does seem to resolve it.
This Works:
PropertyField velocityField = new PropertyField(serializedObject.FindProperty("movementVelocity"));
velocityField.BindProperty(serializedObject.FindProperty("movementVelocity"));
velocityContainer.Add(velocityField);
This Doesn’t:
PropertyField velocityField = new PropertyField(serializedObject.FindProperty("movementVelocity"));
velocityContainer.Add(velocityField);
Edit: Small addition to this: All of this is being called from the initial CreateInspectorGUI(). It’s not being handled in a button-callback or similar event.
hi, @axeldubillet . I got a problem that mixing imgui and ui kit.
//...
public override void OnInspectorGUI()
{
//UnityEngine.Localization.SmartFormat.GlobalVariables
var fp = this.serializedObject.FindProperty("GlobalVariablesGroup");
var editor = Editor.CreateEditor(fp.objectReferenceValue);
editor.OnInspectorGUI();
}
//..
the GlobalVariablesGroup is drawn by ui kit. So like to what you said above, I need to rebind to the
SerializedObject again, but how do I bind it inside the OnInspectorGUI method. I can not override the
CreateInspectorGUI method, since there is a call chain on my end.