Search Unity

Resolved [UI Toolkit] Why UXML and not a standard format?

Discussion in 'UI Toolkit' started by TJHeuvel-net, Aug 26, 2022.

  1. TJHeuvel-net

    TJHeuvel-net

    Joined:
    Jul 31, 2012
    Posts:
    838
    The manual clearly states UXML is inspired by similar formats, but 'includes small differences to provide an efficient way to work with Unity'.

    I'm wondering why the choice has been made to deviate from these standards, and make something new that we should learn? I have experience with HTML, so the difference in UXML really tick me off.

    What was it that made it more efficient, because for me (and i'm assuming other ex-webdevelopers) it really isnt?
     
  2. achimmihca

    achimmihca

    Joined:
    Feb 13, 2016
    Posts:
    280
    > so the difference in UXML really tick me off

    Which difference do you mean? UXML is XML, which is a standard langauge.

    Thing is, Unity does not have the same div, span, checkbox, etc. of web browsers.

    For me, it makes sense that they took the same approach, but with Unity specific objects.
    This is also done by other UI frameworks, e.g. Android, Windows Forms, JavaFX, I think also Qt.
     
    mandisaw likes this.
  3. antoine-unity

    antoine-unity

    Unity Technologies

    Joined:
    Sep 10, 2015
    Posts:
    780
    Hi,

    Thanks for your question, it's a good one. To me the question is pretty much : why isn't UI Toolkit using HTML?

    There isn't a clear point in time where this decision was made, so I can only think of why it wasn't considered. And these are just my opinions at this point :) But for context, I have worked on UI Toolkit since its inception so I have quite a bit of context and ultimately some responsibility for the overall design.

    From my point of view, supporting HTML would have been too ambitious. It would mean that the expectation is that existing HTML can be imported into Unity and expect to work according to existing browser standards.

    If that was a goal for Unity I think we would have looked at ways to actually embed a browser engine in Unity and add capabilities to it. Though the integration with C# and the rest of the Unity ecosystem would be challenging.

    Going the UXML route allowed us to only borrow the concepts we need. I think what we borrow from HTML is mostly that the structure of the document influences the layout, without "layout groups"-type of nodes (VisualElement resembles div). This meshes well with USS which takes care of layout.

    Overall I think we're closer to stuff like WPF where it's expected to leverage a component library that is dedicated to the a specific domain (for us, Editor, Game UI, maybe App UI in the future), which means support for mapping C# classes to UXML (which we are working on improving) was more important from day 1 rather compatibility with HTML Tags.

    With Web Components there is now a clearer path to add functionality to the HTML DOM but I think this was managed purely in JavaScript or higher level frameworks like React otherwise back in 2015-2016.

    Hope this helps understanding where we come from a bit.
     
  4. TJHeuvel-net

    TJHeuvel-net

    Joined:
    Jul 31, 2012
    Posts:
    838
    It does, thanks for taking the time to answer!
     
  5. soleron

    soleron

    Joined:
    Apr 21, 2013
    Posts:
    580
    So it was you!
    Now we know.:p