Popupfield has no uxml, is there a way to include it in the layout?

I am not sure how to go about inserting a PopupField in a specific location if it doesn’t support uxml. I have my current layout all create initially by the UIBuilder and once I had the basics of it sketched out I just saved and started work with the uxml document and the editor file.

I had put 4 enum dropdowns but realized one of the fields was best off being a list, but I want it in the 3rd spot of the 4

How might I get it to layout simialr to this below -

EnumField
EnumField
PopupField
EnumField

  • if I am using the setup that is generated via the Create menu such as below?
        public void OnEnable()
        {
            // Each editor window contains a root VisualElement object
            VisualElement root = rootVisualElement;

            var visualTree = AssetDatabase.LoadAssetAtPath<VisualTreeAsset>("Assets/instance.id/Editor/MyEditor.uxml");
            VisualElement editorLayout = visualTree.CloneTree();
            root.Add(editorLayout);
        }

Is there some sort of… display dummy or placeholder item? Not sure what to call it. Something that I can tie to an item somehow so that I can put it into the uxml to force a specific item created in C# to display in a particular place in the layout?

uxml
<VisualElement name="my-name" />

c#
root.Q<VisualElement>("my.name").Add(ne PopupField());

That worked great, thanks!

The coded ended up like this in case anyone else needs it later.

 r.Q<VisualElement>("RootNode").Add(new PopupField<string>("Root Node", choices, 0) { value = "None" });
1 Like