Search Unity

Feedback Inline Template Bindings

Discussion in 'UI Toolkit' started by Amaron77, May 15, 2020.

  1. Amaron77

    Amaron77

    Joined:
    Jun 16, 2018
    Posts:
    17
    Is there a reason this isn't supported? I think it would make templates a lot more powerful. I'd be even more excited if binding path was a USS property.
     
  2. jonathanma_unity

    jonathanma_unity

    Unity Technologies

    Joined:
    Jan 7, 2019
    Posts:
    229
    Could you elaborate on what you are suggesting? An example would help since it is not super clear from the title.
     
  3. uMathieu

    uMathieu

    Unity Technologies

    Joined:
    Jun 6, 2017
    Posts:
    398
    I<m not sure I understand what you need exactly but maybe the uxml attribute override feature might help. AFAIK it's still undocumented and the documentation team has it on the (quite long) TODO list:

    Here is an example:
    Code (CSharp):
    1. <UXML xmlns="UnityEngine.UIElements">
    2.     <Label name="player-name-label" text="default name" />
    3.     <Label name="player-score-label" text="default score" />
    4. </UXML>
    5.  
    Now I can instantiate this template from another uxml and override some attributes:
    Code (CSharp):
    1. <UXML xmlns="UnityEngine.UIElements" xmlns:uie="UnityEditor.UIElements">
    2.     <Template src="MyTemplate.uxml" name="MyTemplate" />
    3.     <Instance name="player1" template="MyTemplate">
    4.         <AttributeOverrides element-name="player-name-label" text="Amaron77" />
    5.         <AttributeOverrides element-name="player-score-label" text="2" />
    6.     </Instance>
    7.     <Instance name="player2" template="MyTemplate">
    8.         <AttributeOverrides element-name="player-name-label" text="uMathieu" />
    9.         <AttributeOverrides element-name="player-score-label" text="1" />
    10.     </Instance>
    11. </UXML>
    Unfortunately this feature is not yet supported by the UIBuilder so you'll have to type this xml manually

    I agree being able to override the binding path via uss may be nice, but right now, changing the binding-path of an element after it has been bound has no immediate effect: you need to explicitly rebind it...

    adding it to the wish list :)
     
    Onigiri and BinaryCats like this.
  4. Amaron77

    Amaron77

    Joined:
    Jun 16, 2018
    Posts:
    17
    The override is exactly what I needed. With that I can create lots of templates and just plug them into editors as groups of controls. It's a real pity that it's not supported in UI builder yet.

    I guess I should of been more clear. When using UIBuilder you can change style's and it will save them inline to the xml file.

    If you drop in a template file though you can't change anything about the template. You have to accept it as is and can only alter the style of it via USS. That makes templates super limiting in terms of binding them via the UIBuilder. They have to be bound in the editor script manually.

    The override feature could solve this I'll have to look at it soon.
     
    manuelgoellnitz likes this.