Getting this same error now on UIElements UI editors
This was not an issue in a previous version where the UI was working fine, updated to the latest 2019.4 and this now throws any time we use UIElements rather that is creating a custom inspector or even simply selecting a UXML object in the inspector.
Its clearly a bug rather caused by us or not. I see loads of examples of this if I google the exception and Unity UIElements but not seeing any solutions. Has there been a resolution to this or more info on it?
Below is the exception and this is not from running thing we made simply selecting a uxml object created by Unity in the inspector.
ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
System.ThrowHelper.ThrowArgumentOutOfRangeException (System.ExceptionArgument argument, System.ExceptionResource resource) (at <eae584ce26bc40229c1b1aa476bfa589>:0)
System.ThrowHelper.ThrowArgumentOutOfRangeException () (at <eae584ce26bc40229c1b1aa476bfa589>:0)
System.Collections.Generic.List`1[T].get_Item (System.Int32 index) (at <eae584ce26bc40229c1b1aa476bfa589>:0)
UnityEngine.UIElements.StyleSheets.StylePropertyReader.GetValue (System.Int32 index) (at <945577022a524653b365dec2d6094114>:0)
UnityEngine.UIElements.StyleSheets.VisualElementStylesData.ApplyProperties (UnityEngine.UIElements.StyleSheets.StylePropertyReader reader, UnityEngine.UIElements.StyleSheets.InheritedStylesData inheritedStylesData) (at <945577022a524653b365dec2d6094114>:0)
UnityEngine.UIElements.VisualTreeAsset.CloneSetupRecursively (UnityEngine.UIElements.VisualElementAsset root, System.Collections.Generic.Dictionary`2[TKey,TValue] idToChildren, UnityEngine.UIElements.CreationContext context) (at <945577022a524653b365dec2d6094114>:0)
UnityEngine.UIElements.VisualTreeAsset.CloneSetupRecursively (UnityEngine.UIElements.VisualElementAsset root, System.Collections.Generic.Dictionary`2[TKey,TValue] idToChildren, UnityEngine.UIElements.CreationContext context) (at <945577022a524653b365dec2d6094114>:0)
UnityEngine.UIElements.VisualTreeAsset.CloneSetupRecursively (UnityEngine.UIElements.VisualElementAsset root, System.Collections.Generic.Dictionary`2[TKey,TValue] idToChildren, UnityEngine.UIElements.CreationContext context) (at <945577022a524653b365dec2d6094114>:0)
UnityEngine.UIElements.VisualTreeAsset.CloneSetupRecursively (UnityEngine.UIElements.VisualElementAsset root, System.Collections.Generic.Dictionary`2[TKey,TValue] idToChildren, UnityEngine.UIElements.CreationContext context) (at <945577022a524653b365dec2d6094114>:0)
UnityEngine.UIElements.VisualTreeAsset.CloneTree (UnityEngine.UIElements.VisualElement target, System.Collections.Generic.Dictionary`2[TKey,TValue] slotInsertionPoints, System.Collections.Generic.List`1[T] attributeOverrides) (at <945577022a524653b365dec2d6094114>:0)
UnityEngine.UIElements.VisualTreeAsset.CloneTree (UnityEngine.UIElements.VisualElement target, System.Collections.Generic.Dictionary`2[TKey,TValue] slotInsertionPoints) (at <945577022a524653b365dec2d6094114>:0)
UnityEngine.UIElements.VisualTreeAsset.CloneTree (UnityEngine.UIElements.VisualElement target) (at <945577022a524653b365dec2d6094114>:0)
UnityEngine.UIElements.VisualTreeAsset.CloneTree () (at <945577022a524653b365dec2d6094114>:0)
UnityEditor.UIElements.VisualTreeAssetEditor.Render (UnityEngine.UIElements.VisualTreeAsset vta, UnityEngine.Rect r, UnityEngine.GUIStyle background) (at <fc4e84dee5004858ad88e6706bb25889>:0)
UnityEditor.UIElements.VisualTreeAssetEditor.OnPreviewGUI (UnityEngine.Rect r, UnityEngine.GUIStyle background) (at <fc4e84dee5004858ad88e6706bb25889>:0)
UnityEditor.Editor.OnPreviewGUI (UnityEngine.Rect r, UnityEngine.GUIStyle background) (at <fc4e84dee5004858ad88e6706bb25889>:0)
UnityEditor.Editor.OnInteractivePreviewGUI (UnityEngine.Rect r, UnityEngine.GUIStyle background) (at <fc4e84dee5004858ad88e6706bb25889>:0)
UnityEditor.ObjectPreview.DrawPreview (UnityEditor.IPreviewable defaultPreview, UnityEngine.Rect previewArea, UnityEngine.Object[] targets) (at <fc4e84dee5004858ad88e6706bb25889>:0)
UnityEditor.Editor.DrawPreview (UnityEngine.Rect previewArea) (at <fc4e84dee5004858ad88e6706bb25889>:0)
UnityEditor.InspectorWindow.DrawPreviewAndLabels () (at <fc4e84dee5004858ad88e6706bb25889>:0)
UnityEngine.UIElements.IMGUIContainer.DoOnGUI (UnityEngine.Event evt, UnityEngine.Matrix4x4 parentTransform, UnityEngine.Rect clippingRect, System.Boolean isComputingLayout, UnityEngine.Rect layoutSize, System.Action onGUIHandler, System.Boolean canAffectFocus) (at <945577022a524653b365dec2d6094114>:0)
UnityEngine.UIElements.IMGUIContainer.HandleIMGUIEvent (UnityEngine.Event e, UnityEngine.Matrix4x4 worldTransform, UnityEngine.Rect clippingRect, System.Action onGUIHandler, System.Boolean canAffectFocus) (at <945577022a524653b365dec2d6094114>:0)
UnityEngine.UIElements.IMGUIContainer.DoIMGUIRepaint () (at <945577022a524653b365dec2d6094114>:0)
UnityEngine.UIElements.UIR.RenderChainCommand.ExecuteNonDrawMesh (UnityEngine.UIElements.UIR.DrawParams drawParams, System.Boolean straightY, System.Single pixelsPerPoint, System.Exception& immediateException) (at <945577022a524653b365dec2d6094114>:0)
Rethrow as ImmediateModeException
UnityEngine.UIElements.UIR.RenderChain.Render (UnityEngine.Rect viewport, UnityEngine.Matrix4x4 projection, UnityEngine.UIElements.PanelClearFlags clearFlags) (at <945577022a524653b365dec2d6094114>:0)
UnityEngine.UIElements.UIRRepaintUpdater.DrawChain (UnityEngine.Rect viewport, UnityEngine.Matrix4x4 projection) (at <945577022a524653b365dec2d6094114>:0)
UnityEngine.UIElements.UIRRepaintUpdater.Update () (at <945577022a524653b365dec2d6094114>:0)
UnityEngine.UIElements.VisualTreeUpdater.UpdateVisualTreePhase (UnityEngine.UIElements.VisualTreeUpdatePhase phase) (at <945577022a524653b365dec2d6094114>:0)
UnityEngine.UIElements.Panel.UpdateForRepaint () (at <945577022a524653b365dec2d6094114>:0)
UnityEngine.UIElements.Panel.Repaint (UnityEngine.Event e) (at <945577022a524653b365dec2d6094114>:0)
UnityEngine.UIElements.UIElementsUtility.DoDispatch (UnityEngine.UIElements.BaseVisualElementPanel panel) (at <945577022a524653b365dec2d6094114>:0)
UnityEngine.UIElements.UIElementsUtility.ProcessEvent (System.Int32 instanceID, System.IntPtr nativeEventPtr) (at <945577022a524653b365dec2d6094114>:0)
UnityEngine.GUIUtility.ProcessEvent (System.Int32 instanceID, System.IntPtr nativeEventPtr) (at <d7a7ba0654354637944bd8709c6f8668>:0)
Found the issue and all I can say is wow this is horrible.
Your referencing images linked via the path in the asset folder so if they get moved the value is no longer valid and the result is a null ref exception causing every node past that to just break. YIKES
This makes using UI Elements supper fragile.
Please change this to either use GUID of the asset as the reference or if you cant do that at least wrap the walk of the mark up such that when it encounters a reference it cant resolve simply use default for that type and move on dont crash out.