Unable to open UXML file in UI Builder after deleting a referenced Template Asset

Giving another stab at UI Toolkit for Runtime after waiting a year. Things seem a little better and there’s some exciting stuff happening. But I’ve encountered a myriad of issues that I mostly brushed aside until this happened.

  1. Created a functional UXML file for a Pop Up
  2. Created a Template for an element I planned to re-use
  3. Tried to find a way to create a “Variant” template. Not a thing. Got sad.
  4. Duplicated that template, Unpacked the duplicate, made some updates to differentiate it, Saved as a new Template
  5. Decided I didn’t like it, and deleted the 2nd Template Asset while it was still in use on the UXML File.
  6. UI builder shows an error popup with the same message as the exception below and refuses to open the file.
  7. See a previous message about how the missing Template was the problem.
  8. I’m not scared of my IDE. Open the UXML File, delete the offending line, return to the UI Builder slightly annoyed.
  9. Same Popup, same exception, this time without any “Details” mentioned by the error message.
  10. Restart Unity to be sure something weird wasn’t cached.
  11. Same Behaviour.

This can’t be that much of an edge case. If I missed a step “Fixing” the UXML the console should be telling me what is wrong. Assuming it’s not just a bug on the editor’s side. Not to mention, wouldn’t it make sense to replace any missing Templates with a temporary container as an error like we see with prefabs? Not really looking for an answer here, since this might be the first of many issues that make it difficult to help myself. just doing my part for now and I’ll come back and see if things are a bit more stable later.

Other random things I’ll call out here:

  • I can’t “RMB → Properties…” on Object fields in the inspector anymore to inspect them in another window since the transition from IMGUI to UI Toolkit in editor. I used this feature extensively for working with Runtime (Not saved as an asset) Scriptable Objects and quickly checking things without losing my “place” in the inspector and I miss it.
  • If I switch the image type on a VisualElement’s Background from Texture to Sprite, If the Asset has sprite as a sub-asset, it should try to select it. Or the UI for switching the image type should be on top of the object field instead of to the side to encourage setting that first.
  • The UI Builder should have it’s own console window it can dump messages into, or a notification system for non-exception error messages to reduce main window console spam.
  • Some advanced functions for manipulating the UXML hierarchy would be nice, like Adding an Empty Visual Element as a parent of one or more elements.

Unity Version: 2022.3.15f1

Exception:

UI Builder Failed to open Assets/OrderScreen.uxml.uxml asset. This may be due to invalid UXML syntax or UXML syntax the UI Builder does not yet support. Check console for details.
UnityEngine.Debug:LogError (object)
Unity.UI.Builder.BuilderAssetUtilities:ValidateAsset (UnityEngine.UIElements.VisualTreeAsset,string) (at /Users/bokken/build/output/unity/unity/External/MirroredPackageSources/com.unity.ui.builder/Editor/Builder/Utilities/BuilderAssetUtilities.cs:144)
Unity.UI.Builder.BuilderLibraryView:AddItemToTheDocument (Unity.UI.Builder.BuilderLibraryTreeItem) (at /Users/bokken/build/output/unity/unity/External/MirroredPackageSources/com.unity.ui.builder/Editor/Builder/Library/BuilderLibraryView.cs:78)
Unity.UI.Builder.BuilderLibraryTreeView:OnItemsChosen (System.Collections.Generic.IEnumerable`1<object>) (at /Users/bokken/build/output/unity/unity/External/MirroredPackageSources/com.unity.ui.builder/Editor/Builder/Library/BuilderLibraryTreeView.cs:182)
UnityEngine.GUIUtility:ProcessEvent (int,intptr,bool&) (at /Users/bokken/build/output/unity/unity/Modules/IMGUI/GUIUtility.cs:190)

Offending Section of UXML:

<ui:VisualElement name="Prices" style="flex-grow: 1; flex-direction: row; justify-content: space-around;">
                            <ui:Instance template="Price_Label" name="Price_Label" style="justify-content: center;" />
                            <ui:Instance template="MarketPriceLabel" name="MarketPriceLabel" style="justify-content: center;" />
                        </ui:VisualElement>

Error messages generated by Rider before my “Fix”

Assets/OrderScreen.uxml (1,2): Semantic - The specified URI refers to an invalid asset : <null>
Assets/OrderScreen.uxml (20,30): Semantic - Unknown template name 'MarketPriceLabel'

UXML After “Fixing” It.

<ui:VisualElement name="Prices" style="flex-grow: 1; flex-direction: row; justify-content: space-around;">
    <ui:Instance template="Price_Label" name="Price_Label" style="justify-content: center;" />
</ui:VisualElement>

Hello! Thank you for the detailed post. For the main issue about uxml files getting corrupted when we delete a child template I’ll open a bug, because you shouldn’t be able to corrupt files from inside the editor.

As for the rest of the feedback, I might have some answers:

Unfortunately, we are not aiming to have parity with the prefabs workflow at the moment. Ideally, you should be able to have variants of uxml files by just using styles or as you did to create a new uxml file.

Definitely. I think the missing step here was to remove the template tag with the missing reference but you should’ve gotten an error.

This works for me on Unity 6. This could potentially be a bug or something that can’t be backported. I’ll check with the team.

Definitely! This is an issue we are aware of. We introduced a notifications system in the UI Builder in 23.2 but right now the only feature that’s using it’s the preview mode and data binding. We aim to show more useful warnings and errors with this system.

1 Like

Thanks for replying. Maybe I’ll just wait until an LTS version of Unity 6 to take another look.