Query Disabled Item

How can I query a disabled object? I develop a custom editor inspector. I have to query a UIDocument on a disabled gameobject. Because when game object disabled, UIDocument.rootVisualElement is null, I cannot query. How can I query a disabled item?

When a UIDocument component is disabled the visual tree gets released. Meaning there is no visual elements to query.

If you still want them present, but not visible, just flip the visibility of the root visual element.

You can set the display style to none to hide and flex to show.
Be aware, based on my tests the cost of changing displayStyle is almost the same with instantiating new uielement

I just want to query a uidocument and get all buttons. Is not it possible for disabled gameobjects?

No, because there are no visual elements to query. The visual tree only gets built if/when the game object/UI document component is enabled.

so it is bad for me. I develop some editor scripts so I need to access disabled items. I have to use a free text field for element names that will cause some typo errors.

Can your editor script not just re-enable then disable the game object as required?

That’s what I did as a workaround. It won’t be sufficient for me because I have to enable all hierarchy to catch all items in the query. So I quit this idea, I tried to implement my function on a custom visual element. I see, a custom inspector is not available for UI Toolkit custom controls on UIBuilder. So I still search for a solution.

why not just detach/reattach those uielements? I mean instead of disabling/enabling? and before you’re detaching, make sure to cache the index in the hierarchy via vis.indexOf either to a list or just via userData so later on you can do “parent.Insert(index, visualElement)” if you want to insert them back, or in this case “enable” it. this way you can still do normal query on them

With uitoolkit I’ve never had the needs to physically disabled them tbfh.