Question: ObjectField from UI Toolkit inside a PropertyDrawer does not follow the usual rules

Hi there,

I’ve been having trouble with ObjectFields from UI toolkit in property drawers recently.
They render, but their USS seems all over the place.

I tried copying the USS values of GAMEOBJECT (from the screenshot) into the new ObjectField, but it still didn’t follow the visualization of GAMEOBJECT.

Can anyone enlighten me here?
Is it a bug? A regression?

public override VisualElement CreatePropertyGUI(SerializedProperty property)
        {
            return new ObjectField("Foo");
        }

Try adding alignedFieldUssClassName to the ObjectField.

var o = new ObjectField("Foo");
o.AddToClassList(ObjectField.alignedFieldUssClassName);

Beautiful.
Works perfectly.
Thanks a lot.

1 Like