get the rootVisualElement in the 'Editor'

I’ve went through the tutorials and examples in the documentation and in the tutorials. I’m loading the editor window from an inspector element (I believe the example is in the documentation manual section).
Now though I need to hide or disable some of the controls based on other controls values. In the editor window I can register a callback and get the value from the ‘anchor’ field and react appropriately. I can’t do that in the ‘Editor’ though as I cannot find where to get the equivalent to the rootVisualElement (editorwindow) in the editor. Or I cannot find out what it is?

I also tried to find out how to do it directly in the stylesheet(uss) as I used to do it that way in css. No luck though.

Any suggestions, other paths to take?

for instance, in the uxml there is a floatfield defined, display perfectly, binds correctly. In the CreateInspectorGUI it’s not bound until the function returns so the value is 0. Once it is loaded it’s value is bound as ‘45’. So I need to disable/hide 3 other fields in the editor.

Thanks in advance,
Bubba

VisualElement has panel.visualTree which will give you the actual root element containing the dock area and the windows rootVisualElement. So to get the window’s rootVisualElement from any element inside it you can do element.panel.visualTree.ElementAt(1). Hopefully that is what you are looking for

1 Like

You can do this recursively

        public static VisualElement FindRootEditor<T>(this T visualElement, int iteration = 100) where T : VisualElement
        {
            VisualElement prevParent = null;

            while (iteration > 0)
            {
                VisualElement parent = null;

                if (prevParent == null)
                    parent = visualElement.parent;
                else
                    parent = prevParent.parent;

                if (parent != null)
                {
                    prevParent = parent;
                }
                else
                {
                    foreach(var f in prevParent.Children())
                    {
                        if(f.name.Contains("rootVisualContainer"))
                        {
                            return f;
                        }
                    }

                    return null;
                }

                iteration--;
            }

            return null;
        }

Just make sure you use that after the visualElement parented