Hi, I hope this is not an obvious mistake on my part, but I can’t get my property drawer for a class to render inside an editor window using UIElements. The property drawer is not being called at all which suggests that I am somehow not calling the property field correctly?
The property drawer in question (not getting in here)
The class the drawer is referring to:
Finally, the part in my EditorWindow where I am trying to add the visual element. This is the first time I’m using property fields in combination with UIElements and I feel like this might be the sticking point:
This part of the code is being called and “prop_Dialogue” / “prop_dialogue_reaction” are not null in the above.
Is my way of implementing the custom drawer correct? I am not using any IMGUI in my editor window nor the property drawer.
One thing that always trips me up: Inside an EditorWindow you will need to call .Bind(serializedRule) yourself (preferably on the “root” visualelement that describes your object). If you look into how the constructor for PropertyField is implemented you can see that it only sets the binding path and leaves the actual binding to someone else: the inspector window for normal property drawers / editors or the EditorWindow.
1 Like
Many thanks, adding
"rootVisualElement.Bind(serializedRule); "
did the trick! Tricky little line indeed.
I’ll need to do a bit more research on this, binding it to other visual elements in my editor window doesn’t work (it still doesn’t show up), and the drawer will also disappear if I reopen the window, but at least I know in what direction to move ahead. Thanks again.
Update for the curious: You have to Bind the serialized Object to the actual PropertyField which inherits from VisualElement in order for it to work. Binding it to the root doesn’t work! This means in the case above I needed to call
prop_dialogue_reaction.Bind(serializedRule)
Hope that helps.