NullReferenceException when trying to rename a control in UI Builder

Not entirely sure how to reproduce it. But this is how it usually happens for me:

  • Add a UI Document into the scene
  • While running, do something that causes an error related to the UI. E.g., assign NaN to the style.width of a control.
  • After stopping execution, if I open the UIBuilder window of that uxml file, it reports an error listed in the following. I am unable to interact with the hierarchy until I restart the editor.
  • If I try to click on a control in the hierarchy, a window appears saying "UI Builder failed to open filename.uxml asset. This may be due to invalid UXML syntax or UXML syntax the UI Builder does not yet support. Check console for details."Console output is listed after the first code block (something to do with “VisualElementAsset has a RuleIndex but no inlineStyleSheet”
    I have not edited the UXML file directly.
NullReferenceException: Object reference not set to an instance of an object
Unity.UI.Builder.StyleSheetExtensions.GetRule (UnityEngine.UIElements.StyleSheet styleSheet, System.Int32 index) (at Library/PackageCache/com.unity.ui.builder@1.0.0-preview.3/Editor/Utilities/StyleSheetExtensions/StyleSheetExtensions.cs:138)
Unity.UI.Builder.VisualTreeAssetExtensions.GetOrCreateInlineStyleRule (UnityEngine.UIElements.VisualTreeAsset vta, UnityEngine.UIElements.VisualElementAsset vea, System.Boolean& wasCreated) (at Library/PackageCache/com.unity.ui.builder@1.0.0-preview.3/Editor/Utilities/VisualTreeAssetExtensions/VisualTreeAssetExtensions.cs:467)
Unity.UI.Builder.VisualTreeAssetExtensions.GetOrCreateInlineStyleRule (UnityEngine.UIElements.VisualTreeAsset vta, UnityEngine.UIElements.VisualElementAsset vea) (at Library/PackageCache/com.unity.ui.builder@1.0.0-preview.3/Editor/Utilities/VisualTreeAssetExtensions/VisualTreeAssetExtensions.cs:450)
Unity.UI.Builder.BuilderInspector.get_currentRule () (at Library/PackageCache/com.unity.ui.builder@1.0.0-preview.3/Editor/Builder/Inspector/BuilderInspector.cs:132)
Unity.UI.Builder.BuilderInspectorStyleFields.get_currentRule () (at Library/PackageCache/com.unity.ui.builder@1.0.0-preview.3/Editor/Builder/Inspector/BuilderInspectorStyleFields.cs:27)
Unity.UI.Builder.BuilderInspectorStyleFields.RefreshStyleField (System.String styleName, UnityEngine.UIElements.VisualElement fieldElement) (at Library/PackageCache/com.unity.ui.builder@1.0.0-preview.3/Editor/Builder/Inspector/BuilderInspectorStyleFields.cs:472)
Unity.UI.Builder.BuilderInspectorLocalStyles.Refresh () (at Library/PackageCache/com.unity.ui.builder@1.0.0-preview.3/Editor/Builder/Inspector/BuilderInspectorLocalStyles.cs:166)
Unity.UI.Builder.BuilderInspector.RefreshUI () (at Library/PackageCache/com.unity.ui.builder@1.0.0-preview.3/Editor/Builder/Inspector/BuilderInspector.cs:450)
Unity.UI.Builder.BuilderInspector.SelectionChanged () (at Library/PackageCache/com.unity.ui.builder@1.0.0-preview.3/Editor/Builder/Inspector/BuilderInspector.cs:497)
Unity.UI.Builder.BuilderSelection.NotifyOfSelectionChange (Unity.UI.Builder.IBuilderSelectionNotifier source) (at Library/PackageCache/com.unity.ui.builder@1.0.0-preview.3/Editor/Builder/BuilderSelection.cs:282)
Unity.UI.Builder.BuilderSelection.Select (Unity.UI.Builder.IBuilderSelectionNotifier source, UnityEngine.UIElements.VisualElement ve) (at Library/PackageCache/com.unity.ui.builder@1.0.0-preview.3/Editor/Builder/BuilderSelection.cs:157)
Unity.UI.Builder.BuilderElementContextMenu+<>c__DisplayClass22_0.<BuildElementContextualMenu>b__2 (UnityEngine.UIElements.DropdownMenuAction a) (at Library/PackageCache/com.unity.ui.builder@1.0.0-preview.3/Editor/Builder/Utilities/BuilderElementContextMenu.cs:158)
UnityEngine.UIElements.DropdownMenuAction.Execute () (at Library/PackageCache/com.unity.ui@1.0.0-preview.3/Core/DropdownMenu.cs:189)
UnityEditor.UIElements.EditorMenuExtensions+<>c__DisplayClass0_0.<PrepareMenu>b__0 () (at <f77486451c0e4476a0c4fd6818e21c8a>:0)
UnityEditor.GenericMenu.CatchMenu (System.Object userData, System.String[] options, System.Int32 selected) (at <f77486451c0e4476a0c4fd6818e21c8a>:0)
VisualElementAsset has a RuleIndex but no inlineStyleSheet
UnityEngine.Debug:LogWarning(Object)
Unity.UI.Builder.VisualTreeAssetToUXML:GenerateUXMLRecursive(VisualTreeAsset, String, VisualElementAsset, Dictionary`2, StringBuilder, Int32, Boolean) (at Library/PackageCache/com.unity.ui.builder@1.0.0-preview.3/Editor/Utilities/VisualTreeAssetExtensions/VisualTreeAssetToUXML.cs:259)
Unity.UI.Builder.VisualTreeAssetToUXML:GenerateUXMLFromRootElements(VisualTreeAsset, Dictionary`2, StringBuilder, String, Boolean) (at Library/PackageCache/com.unity.ui.builder@1.0.0-preview.3/Editor/Utilities/VisualTreeAssetExtensions/VisualTreeAssetToUXML.cs:449)
Unity.UI.Builder.VisualTreeAssetToUXML:GenerateUXML(VisualTreeAsset, String, Boolean) (at Library/PackageCache/com.unity.ui.builder@1.0.0-preview.3/Editor/Utilities/VisualTreeAssetExtensions/VisualTreeAssetToUXML.cs:480)
Unity.UI.Builder.VisualTreeAssetExtensions:GenerateUXML(VisualTreeAsset, String, Boolean) (at Library/PackageCache/com.unity.ui.builder@1.0.0-preview.3/Editor/Utilities/VisualTreeAssetExtensions/VisualTreeAssetExtensions.cs:63)
Unity.UI.Builder.BuilderUxmlPreview:GenerateUXMLText() (at Library/PackageCache/com.unity.ui.builder@1.0.0-preview.3/Editor/Builder/Previews/BuilderUxmlPreview.cs:22)
Unity.UI.Builder.BuilderUxmlPreview:RefreshUXML() (at Library/PackageCache/com.unity.ui.builder@1.0.0-preview.3/Editor/Builder/Previews/BuilderUxmlPreview.cs:30)
Unity.UI.Builder.BuilderUxmlPreview:SelectionChanged() (at Library/PackageCache/com.unity.ui.builder@1.0.0-preview.3/Editor/Builder/Previews/BuilderUxmlPreview.cs:47)
Unity.UI.Builder.BuilderSelection:NotifyOfSelectionChange(IBuilderSelectionNotifier) (at Library/PackageCache/com.unity.ui.builder@1.0.0-preview.3/Editor/Builder/BuilderSelection.cs:282)
Unity.UI.Builder.BuilderSelection:ClearSelection(IBuilderSelectionNotifier, Boolean) (at Library/PackageCache/com.unity.ui.builder@1.0.0-preview.3/Editor/Builder/BuilderSelection.cs:200)
Unity.UI.Builder.BuilderExplorer:ElementSelectionChanged(List`1) (at Library/PackageCache/com.unity.ui.builder@1.0.0-preview.3/Editor/Builder/Explorer/BuilderExplorer.cs:126)
Unity.UI.Builder.ElementHierarchyView:OnSelectionChange(IEnumerable`1) (at Library/PackageCache/com.unity.ui.builder@1.0.0-preview.3/Editor/Utilities/ElementHierarchyView/ElementHierarchyView.cs:455)
UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr, Boolean&)

Please report this as a bug via Unity’s built-in Bug Reporter so it can be properly tracked. If you can also include the exact code you used to invalidate the style (using a NaN), that would also help us a lot. Thanks!