Add item footer crash in listview

Hi there!
So my question is really very simple.
I have two .uxml files, one for a frame (with a listView) and one for an item (that is to be added to the listView)
I have added a add/remove footer to that listview.

Things work As You’d Expect™ in Editor mode (so if my class is derived from EditorWindow), I click ‘+’ and a new item pops in, life is good.
But if I create a UIDocument in the scene and follow exactly the same procedure I get a crash when pressing either ‘+’ or ‘-’. I imagine I need to implement something (that is implemented for me in the Editor version, but can’t figure out what it is)

The callstack is:

NullReferenceException: Object reference not set to an instance of an object
UnityEngine.UIElements.ListView.AddItems (System.Int32 itemCount) (at /Users/bokken/buildslave/unity/build/ModuleOverrides/com.unity.ui/Core/Controls/ListView.cs:383)
UnityEngine.UIElements.ListView.OnAddClicked () (at /Users/bokken/buildslave/unity/build/ModuleOverrides/com.unity.ui/Core/Controls/ListView.cs:447)
UnityEngine.UIElements.Clickable.Invoke (UnityEngine.UIElements.EventBase evt) (at /Users/bokken/buildslave/unity/build/ModuleOverrides/com.unity.ui/Core/Clickable.cs:292)
UnityEngine.UIElements.Clickable.ProcessUpEvent (UnityEngine.UIElements.EventBase evt, UnityEngine.Vector2 localPosition, System.Int32 pointerId) (at /Users/bokken/buildslave/unity/build/ModuleOverrides/com.unity.ui/Core/Clickable.cs:380)
UnityEngine.UIElements.Clickable.OnMouseUp (UnityEngine.UIElements.MouseUpEvent evt) (at /Users/bokken/buildslave/unity/build/ModuleOverrides/com.unity.ui/Core/Clickable.cs:173)
UnityEngine.UIElements.EventCallbackFunctor`1[TEventType].Invoke (UnityEngine.UIElements.EventBase evt, UnityEngine.UIElements.PropagationPhase propagationPhase) (at /Users/bokken/buildslave/unity/build/ModuleOverrides/com.unity.ui/Core/Events/EventCallback.cs:79)
UnityEngine.UIElements.EventCallbackRegistry.InvokeCallbacks (UnityEngine.UIElements.EventBase evt, UnityEngine.UIElements.PropagationPhase propagationPhase) (at /Users/bokken/buildslave/unity/build/ModuleOverrides/com.unity.ui/Core/Events/EventCallbackRegistry.cs:353)
UnityEngine.UIElements.CallbackEventHandler.HandleEvent (UnityEngine.UIElements.EventBase evt) (at /Users/bokken/buildslave/unity/build/ModuleOverrides/com.unity.ui/Core/Events/EventHandler.cs:186)
UnityEngine.UIElements.TextElement.HandleEvent (UnityEngine.UIElements.EventBase evt) (at /Users/bokken/buildslave/unity/build/ModuleOverrides/com.unity.ui/Core/TextElement.cs:101)
UnityEngine.UIElements.EventDispatchUtilities.PropagateEvent (UnityEngine.UIElements.EventBase evt) (at /Users/bokken/buildslave/unity/build/ModuleOverrides/com.unity.ui/Core/Events/IEventDispatchingStrategy.cs:113)

Heeeelp? :smile:

Okay, it was my own bloody fault. When moving my code from the editor mode I kept using

var visualTree = AssetDatabase.LoadAssetAtPath<VisualTreeAsset>("Assets/Main.uxml");

Instead of using

var rootVisualElement = GetComponent<UIDocument>().rootVisualElement;

Of course then the bind/make items callbacks where not set and that probably is why the inner code ended up with the NullRefernceException

…it would have helped to have the error message being a tad clearer (or even clickable to go the code that crashed), “users/bokken/buildslave” is definitely not part of my packageCache structure :slight_smile: