Search Unity

  1. Unity 2019.2 is now released.
    Dismiss Notice

How use templates?

Discussion in 'UIElements' started by Devi-User, Nov 20, 2018.

  1. Devi-User

    Devi-User

    Joined:
    Apr 30, 2016
    Posts:
    61
    I’m trying to learn how to work with the Template and Instance tags.

    However, I can not achieve the behavior in which it works.
    If I post the Template tag after Instance, I’ll get an error

    Code (csharp):
    1. <UXML xmlns:ui="UnityEngine.Experimental.UIElements">
    2.     <ui:VisualElement>
    3.         <ui:Instance template="myTemplate" />
    4.       </ui:VisualElement>
    5.       <ui:Template path="myTemplate" name="myTemplate">
    6.         <ui:VisualElement name="item">
    7.             <ui:Button name="item-button" text="Item"/>
    8.         </ui:VisualElement>
    9.       </ui:Template>
    10. </UXML>
    11.  
    Error:

    Semantic - Unknown template name 'myTemplate'
    UnityEditor.AssetPostprocessingInternal:PostprocessAllAssets(String[], String[], String[], String[], String[])


    If teplate tag before instance:

    Could not resolve template with name 'myTemplate'
    UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr)


    I also tried to save the template in a separate file in 'Resources' folder. If you 'forget' to remove the code from the main file, the errors completely disappear, but nothing happens. If you delete the template from the main file, there will be an error.

    Semantic - Unknown template name 'myTemplate'
    UnityEditor.AssetPostprocessingInternal:PostprocessAllAssets(String[], String[], String[], String[], String[])


    Unity 2019. What am I doing wrong?
     
  2. Devi-User

    Devi-User

    Joined:
    Apr 30, 2016
    Posts:
    61
  3. uDamian

    uDamian

    Unity Technologies

    Joined:
    Dec 11, 2017
    Posts:
    281
    Sorry to be the bearer of bad news but Slots will be removed from UXML in 2019.1. I wouldn't rely on them too heavily if you want a smoother transition. We'll have a better UXML reuse API eventually in a different form.
     
    Devi-User likes this.