ArgumentNullException on creating new Inventory Items (and also a workaround)

So I’ve been getting a couple instances of this ArgumentNullException (almost) every time I try to change something basic (like the sprite icon) of an InventoryItem to something new. I get a few instances of this error in my console, but the game seems to otherwise work fine. Even if I change it back to an old sprite it still reocurrs. If I comment out the new line for slots[10] it still happens. But if I exit Unity and re-launch the errors is gone. If I again try to change the sprite, it happens again. If I exit and relaunch Unity the error is gone. Also - sometimes I’m lucky and the error doesn’t show up at all.

My guess is there’s some cache that’s not being refreshed when you change a scriptable object for an InventoryItem.

I think my workaround works but I’d still like to understand what’s going on.

code:

        private void Awake()
        {
            slots = new InventoryItem[inventorySize];
            slots[0] = InventoryItem.GetFromID("71e73607-4bac-4e42-b7d6-5e6f91e92dc4");
            slots[1] = InventoryItem.GetFromID("0aa7c8b8-4796-42aa-89d0-9d100ea67d7b");
            slots[10] = InventoryItem.GetFromID("0f368cbf-6818-4367-bbab-0a1ba8ba3bd5");
        }
ArgumentNullException: Value cannot be null.
Parameter name: _unity_self
UnityEditor.SerializedObject.FindProperty (System.String propertyPath) (at <da771086bc2e4cfc9ad0a72e083a7f98>:0)
UnityEditor.UIElements.Bindings.SerializedObjectBindingContext.BindPropertyRelative (UnityEngine.UIElements.IBindable field, UnityEditor.SerializedProperty parentProperty) (at <8ad9ecbe25e14b10b6dde783af6e4aa2>:0)
UnityEditor.UIElements.Bindings.SerializedObjectBindingContext.BindTree (UnityEngine.UIElements.VisualElement element, UnityEditor.SerializedProperty parentProperty) (at <8ad9ecbe25e14b10b6dde783af6e4aa2>:0)
UnityEditor.UIElements.Bindings.SerializedObjectBindingContext.ContinueBinding (UnityEngine.UIElements.VisualElement element, UnityEditor.SerializedProperty parentProperty) (at <8ad9ecbe25e14b10b6dde783af6e4aa2>:0)
UnityEditor.UIElements.Bindings.DefaultSerializedObjectBindingImplementation+BindingRequest.Bind (UnityEngine.UIElements.VisualElement element) (at <8ad9ecbe25e14b10b6dde783af6e4aa2>:0)
UnityEngine.UIElements.VisualTreeBindingsUpdater.Update () (at <e66f217a64a747d48b478f0d70978704>:0)
UnityEngine.UIElements.VisualTreeUpdater.UpdateVisualTreePhase (UnityEngine.UIElements.VisualTreeUpdatePhase phase) (at <e66f217a64a747d48b478f0d70978704>:0)
UnityEngine.UIElements.Panel.UpdateBindings () (at <e66f217a64a747d48b478f0d70978704>:0)
UnityEngine.UIElements.UIElementsUtility.UnityEngine.UIElements.IUIElementsUtility.UpdateSchedulers () (at <e66f217a64a747d48b478f0d70978704>:0)
UnityEngine.UIElements.UIEventRegistration.UpdateSchedulers () (at <e66f217a64a747d48b478f0d70978704>:0)
UnityEditor.RetainedMode.UpdateSchedulers () (at <8ad9ecbe25e14b10b6dde783af6e4aa2>:0)

There’s a chance that the domain isn’t reloading when you hti play. This causes statics like the static Dictionary that InventoryItem uses not to be reloaded.
Go into Edit/Project Settings/Editor and look for the Enter Play Mode Options.
Uncheck this box, or make sure that Reload Domain is checked when the Play Mode Options are selected.


Beyond that, I wouldn’t spend a great deal more time on this issue. The current configuration of the Inventory is temporary, and will be replaced by a structure which includes the item and quantity rather than simply an InventoryItem. The code we’re using in this section is for teaching the basics and will not be the final Inventory code.

Enter Play Mode Options was not selected. I’ll pause on spending any more time on this based on your advice this is temporary code.

Thanks again!

P.S. Getting a weird 500 error when I try to mark something as solution. I tried logging in from a private browsing window and same thing.

Quirk in the forum codes. It still marks the solution, it just throws the error to annoy us.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms