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