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

Bug Using a template from a custom package sometimes throws errors

Discussion in 'UI Toolkit' started by XVRsim, Dec 16, 2020.

  1. XVRsim

    XVRsim

    Joined:
    Jan 11, 2018
    Posts:
    1
    Because we have multiple Unity projects that we want to use the same GUI style for I created a package which contains our default controls, such as buttons, with their default styling. This seems to work fine in the UI Builder, I can add them to my GUI and they show up in runtime.

    Occasionally though when I hit save in the UI Builder I get a set of errors "Template declaration requires a path or src attribute referencing another UXML file" and then "Unknown template name Button". Full errors below:

    Code (CSharp):
    1. Assets/Scripts/AnimationSelectionTree.uxml (1,2): Semantic - 'Template' declaration requires a 'path' or 'src' attribute referencing another UXML file
    2. UnityEditor.AssetDatabase:Refresh ()
    3. Unity.UI.Builder.BuilderDocumentOpenUXML:SaveNewDocument (UnityEngine.UIElements.VisualElement,bool,bool&,string) (at Library/PackageCache/com.unity.ui.builder@1.0.0-preview.11/Editor/Builder/Document/BuilderDocumentOpenUXML.cs:475)
    4. Unity.UI.Builder.BuilderDocument:SaveNewDocument (UnityEngine.UIElements.VisualElement,bool,bool&,string) (at Library/PackageCache/com.unity.ui.builder@1.0.0-preview.11/Editor/Builder/Document/BuilderDocument.cs:271)
    5. Unity.UI.Builder.BuilderToolbar:SaveDocument (bool) (at Library/PackageCache/com.unity.ui.builder@1.0.0-preview.11/Editor/Builder/Toolbar/BuilderToolbar.cs:287)
    6. Unity.UI.Builder.BuilderCommandHandler:OnSaveDocument (UnityEngine.UIElements.KeyUpEvent) (at Library/PackageCache/com.unity.ui.builder@1.0.0-preview.11/Editor/Builder/Utilities/BuilderCommandHandler.cs:147)
    7. UnityEngine.GUIUtility:ProcessEvent (int,intptr,bool&)
    Code (CSharp):
    1. Assets/Scripts/AnimationSelectionTree.uxml (5,14): Semantic - Unknown template name 'Button'
    2. UnityEditor.AssetDatabase:Refresh ()
    3. Unity.UI.Builder.BuilderDocumentOpenUXML:SaveNewDocument (UnityEngine.UIElements.VisualElement,bool,bool&,string) (at Library/PackageCache/com.unity.ui.builder@1.0.0-preview.11/Editor/Builder/Document/BuilderDocumentOpenUXML.cs:475)
    4. Unity.UI.Builder.BuilderDocument:SaveNewDocument (UnityEngine.UIElements.VisualElement,bool,bool&,string) (at Library/PackageCache/com.unity.ui.builder@1.0.0-preview.11/Editor/Builder/Document/BuilderDocument.cs:271)
    5. Unity.UI.Builder.BuilderToolbar:SaveDocument (bool) (at Library/PackageCache/com.unity.ui.builder@1.0.0-preview.11/Editor/Builder/Toolbar/BuilderToolbar.cs:287)
    6. Unity.UI.Builder.BuilderCommandHandler:OnSaveDocument (UnityEngine.UIElements.KeyUpEvent) (at Library/PackageCache/com.unity.ui.builder@1.0.0-preview.11/Editor/Builder/Utilities/BuilderCommandHandler.cs:147)
    7. UnityEngine.GUIUtility:ProcessEvent (int,intptr,bool&)

    After that the buttons get deleted and I need to re-add them. It only happens occasionally, the rest of the time the file saves just fine.

    Button template:
    Code (CSharp):
    1. <ui:UXML xmlns:ui="UnityEngine.UIElements" xmlns:uie="UnityEditor.UIElements" xsi="http://www.w3.org/2001/XMLSchema-instance" engine="UnityEngine.UIElements" editor="UnityEditor.UIElements" noNamespaceSchemaLocation="../../../../../../UIElementsSchema/UIElements.xsd" editor-extension-mode="False">
    2.     <Style src="Button.uss" />
    3.     <ui:Button text="Button" display-tooltip-when-elided="false" name="Button" class="button" />
    4. </ui:UXML>
    UI Builder generated template:
    Code (CSharp):
    1. <ui:UXML xmlns:ui="UnityEngine.UIElements" xmlns:uie="UnityEditor.UIElements" xmlns="UnityEngine.UIElements" xsi="http://www.w3.org/2001/XMLSchema-instance" editor-extension-mode="False">
    2.     <ui:Template name="Button" src="/Packages/com.xvr.ui/Core/Button.uxml" />
    3.     <ui:VisualElement name="rootContainer">
    4.         <ui:VisualElement name="TabContainer" style="height: 41px; justify-content: flex-start; align-items: stretch; flex-direction: row; background-color: rgb(25, 25, 24);">
    5.             <ui:Instance template="Button" name="Tab1" />
    6.             <ui:Instance template="Button" name="Tab2" />
    7.         </ui:VisualElement>
    8.         <ui:VisualElement name="TabBody1" style="height: 336px; background-color: rgb(25, 25, 24); border-left-color: rgb(68, 72, 73); border-right-color: rgb(68, 72, 73); border-top-color: rgb(68, 72, 73); border-bottom-color: rgb(68, 72, 73); border-top-width: 2px;">
    9.             <ui:ListView focusable="true" name="ScrollView" style="height: 385px;" />
    10.         </ui:VisualElement>
    11.     </ui:VisualElement>
    12. </ui:UXML>
     
  2. JuliaP_Unity

    JuliaP_Unity

    Unity Technologies

    Joined:
    Mar 26, 2020
    Posts:
    666
    Hello! We can confirm this should be working and not showing errors, but there may be an instability playing a part here. We have 2 questions for you:
    1- Can you reproduce this reliably? E.g. if you do this/that actions the errors will pop. If yes, please let us know.
    2- Are you using the "Open Sub-Document" feature from the UI Builder to edit your template in-place?
     
  3. StephanieRowlinson

    StephanieRowlinson

    Joined:
    Jul 23, 2014
    Posts:
    136
    OP here.

    I found one consistent way of reproducing the error and submitted a bug report. Casenr: 1300134

    I wasn't using the sub-document functionality, this is all in the main document.
     
  4. JuliaP_Unity

    JuliaP_Unity

    Unity Technologies

    Joined:
    Mar 26, 2020
    Posts:
    666
    Thank you for reporting! We'll be checking the case and updating its status there :)
     
  5. Predulus

    Predulus

    Joined:
    Feb 5, 2018
    Posts:
    89
    I just had this happen in 2020.3.21f1, Win 10
     
  6. JuliaP_Unity

    JuliaP_Unity

    Unity Technologies

    Joined:
    Mar 26, 2020
    Posts:
    666
    Hello, the original case reported ended up closed because QA couldn't reproduce with the information provided. If you have a sample project we can use for investigating, please open a new bug using Help > Report a Bug inside Unity. Thanks!