1
votes

So for the past couple of days I've been trying out the new Unity UI Builder and I came across the following issue: Whenever you simply add a Vector3 field to the uxml and run the game the Vector3 field is scaled incorrectly. In the editor it looks like any Vector3 field would, just like the Unity Editor itself has. Below is an example image and the uxml.

Vector3 field example

<ui:UXML xmlns:ui="UnityEngine.UIElements" xmlns:uie="UnityEditor.UIElements">
    <ui:VisualElement style="flex-grow: 1; position: absolute; height: 100%; width: 100%; justify-content: center; align-items: flex-start;">
        <ui:VisualElement>
            <uie:Vector3Field label="Vec3 Field" />
        </ui:VisualElement>
    </ui:VisualElement>
</ui:UXML>

I have messed around with every field presented to me in the builder without any success. I could do away with the Vector3 field and create my own but that would take more time as I'd need to dive deeper into the source code. I hope someone can help me out. If the issue does seem to be common I'll report it to the Unity devs.

Thanks in advance!

1
Try making an actual build, because this xmlns:uie="UnityEditor.UIElements" will likely throw you an exception looking for this UnityEditor.UIElements.Vector3Field class.Andrew Łukasik
@AndrewŁukasik I made a build as you suggested and it turns out you're absolutely right: imgur.com/a/E1LkYWu Is there a way to fix this or can I just not use the Vector3 field for in game UI?unknown
UnityEditor.* classes are for editor only, so we need to use UnityEngine.* ones or create our own container types for runtime use (it's not that hard to display vector3 as it's just 3 x FloatField)Andrew Łukasik
@AndrewŁukasik Thank you for the advice, I'll try and see if I can make some custom elements for my UI then. You should add this as an answer so I can mark the solution.unknown

1 Answers

1
votes

If you're seeing UnityEditor.* anywhere in your uxml then be aware that this panel won't work outside unity editor (exception on build). And since UnityEditor.UIElements.Vector3Field is editor specific - it needs to be substituted with something else.

So far, my solutions to this are:

  • Just use UnityEngine.UIElements.Label instead (x1 or x3)
  • Use UnityEngine.UIElements.Slider x 3 (when input is needed) + EventSystem with Event Generation field set to IMGUI Events
  • Or - my own custom class inheriting from VisualElement to handle this case

PS: UIElements is still in development so this may change.