Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

How do I "expose" properties in uxml files? How do I add elements to childs in uxml?

Discussion in 'UI Toolkit' started by Immanuel-Scholz, Apr 25, 2021.

  1. Immanuel-Scholz

    Immanuel-Scholz

    Joined:
    Jun 8, 2013
    Posts:
    221
    Hi,

    I am trying to design an UI for runtime use.

    When creating an uxml, how do I make properties from inside the uxml to be changeable in places where I want to use the uxml?

    Also, how do I add elements to containers inside an uxml? The childs seem to be read-only in the builder.
     
  2. AlainL_Unity

    AlainL_Unity

    Unity Technologies

    Joined:
    Apr 6, 2021
    Posts:
    6
    Hi,

    For your first question, please have a look at this thread. It shows how to instantiate uxml files and modify element properties such as button text: https://forum.unity.com/threads/how-to-make-an-item-in-a-listview-from-a-uxml-template.1100638/

    About your second question: you should be able to simply drag and drop UI Elements as children of a VisualElement container using UI Builder. Is is what you're trying to achieve? If not, could you provide further details please?

    Regards,
    Alain
     
  3. Immanuel-Scholz

    Immanuel-Scholz

    Joined:
    Jun 8, 2013
    Posts:
    221
    I am trying to gauge the possibilities in UI Toolkit to create common controls and reusable parts of the UI. I managed so far to include other UXML files inside of others. One video referred to it as similar to "nested prefabs". In the sample project from Unity, for example, the main menu is composed of 3 UXML for the options, the credits and the actual game UI.

    However, without the ability to customize the dragged-in UXML files, I find this feature rather limiting.

    For example, lets say I have an game with several UI's that display detail information of things you can click in the world. There are lots of different categories like buildings, units, spells, items, buffs, whatever. Allthough they have some common things like a name, many of their properties are different. Now lets say I want to create some commonly used UXML sub-parts for things like the "Header label plus some type label, plus the close-button plus tooltips for them plus a frame plus some common buttons on the button". These should be the same for all (or many) of the different types. There would be an area in the middle where the differences are. Lets call this "CommonDetailPanelParts.uxml"

    How would I expose properties like the text on the type label, so I can customize it depending on the place where I use it?

    How would I add childs to the area in the middle? It is an Visual Element inside the CommonDetailPanelParts.uxml, but when I drag that CommonDetailPanelParts.uxml into, lets say "UnitDetails.uxml", then all interiour becomes read-only.