NullReferenceException: SerializedObject of SerializedProperty has been Disposed

I am getting this error randomly after updating to the latest version of unity ( 2022.2.21f1 ) NullReferenceException: SerializedObject of SerializedProperty has been Disposed. I am unable to figure out what is causing this issue, error log wont take me to the code that is the issue. If I restart unity it goes away. If i enter playmode and then exit the error will start again. I get thousands of these errors.

EDIT: I found that this issue happens when selecting any object in the editor. If I deselect all objects so I have nothing selected I do not get this error

EDIT: Restarting unity, deleting library folder, resetting ui. Fixes the issue for a few minutes then the error returns.

EDIT: Upgraded to 2022.3.0f1 and am running into the issue less but seems to occur when messing with array lists in the inspector, also still happening when selection any object in the scene view

NullReferenceException: SerializedObject of SerializedProperty has been Disposed.
UnityEditor.SerializedProperty.get_objectReferenceInstanceIDValue () (at <a445319feeee47ac85466210448edf2f>:0)
UnityEditor.EditorGUIUtility.ObjectContent (UnityEngine.Object obj, System.Type type, UnityEditor.SerializedProperty property, UnityEditor.EditorGUI+ObjectFieldValidator validator) (at <a445319feeee47ac85466210448edf2f>:0)
UnityEditor.UIElements.ObjectField+ObjectFieldDisplay.Update () (at <a445319feeee47ac85466210448edf2f>:0)
UnityEditor.UIElements.ObjectField.UpdateDisplay () (at <a445319feeee47ac85466210448edf2f>:0)
UnityEngine.UIElements.VisualElement+SimpleScheduledItem.PerformTimerUpdate (UnityEngine.UIElements.TimerState state) (at <618b8429084e4d328aacffdfa23cfc2d>:0)
UnityEngine.UIElements.TimerEventScheduler.UpdateScheduledEvents () (at <618b8429084e4d328aacffdfa23cfc2d>:0)
UnityEngine.UIElements.UIElementsUtility.UnityEngine.UIElements.IUIElementsUtility.UpdateSchedulers () (at <618b8429084e4d328aacffdfa23cfc2d>:0)
UnityEngine.UIElements.UIEventRegistration.UpdateSchedulers () (at <618b8429084e4d328aacffdfa23cfc2d>:0)
UnityEditor.RetainedMode.UpdateSchedulers () (at <a7717f1c634f4059922ea89761126092>:0)

We’re having this bug too since upgrading to 2022.3.6f1. We’re also thinking it’s related to arrays

J’ai le même problème avec deux tableaux justement qui ne s’affichent plus dans l’inspecteur…

Having the same issue. Started this week after a complex logic implementation using a array of struct and a few <int,int> dictionarys (declared inside the scope of the method) in a MonoBehaviour class.

This public array of struct already existed before and was consumed by simpler methods in this and other classes, so I believe it is not related to its existence in the serialization of this class fields.

I’m using Unity 2022.3.7f1

EDIT:
Useful information: happens mostly when attached to Visual Studio for debug.
After exiting play mode the exception continues to throw until closing the Editor.

NullReferenceException: SerializedObject of SerializedProperty has been Disposed.
UnityEditor.SerializedProperty.Verify (UnityEditor.SerializedProperty+VerifyFlags verifyFlags) (at <97436df440ca462884c5332c1d8ebbe7>:0)
UnityEditor.SerializedProperty.get_objectReferenceInstanceIDValue () (at <97436df440ca462884c5332c1d8ebbe7>:0)
UnityEditor.EditorGUIUtility.ObjectContent (UnityEngine.Object obj, System.Type type, UnityEditor.SerializedProperty property, UnityEditor.EditorGUI+ObjectFieldValidator validator) (at <97436df440ca462884c5332c1d8ebbe7>:0)
UnityEditor.UIElements.ObjectField+ObjectFieldDisplay.Update () (at <97436df440ca462884c5332c1d8ebbe7>:0)
UnityEditor.UIElements.ObjectField.UpdateDisplay () (at <97436df440ca462884c5332c1d8ebbe7>:0)
UnityEngine.UIElements.VisualElement+SimpleScheduledItem.PerformTimerUpdate (UnityEngine.UIElements.TimerState state) (at <9d7fc877145d4138982bf12cdd3484c6>:0)
UnityEngine.UIElements.TimerEventScheduler.UpdateScheduledEvents () (at <9d7fc877145d4138982bf12cdd3484c6>:0)
UnityEngine.UIElements.UIElementsUtility.UnityEngine.UIElements.IUIElementsUtility.UpdateSchedulers () (at <9d7fc877145d4138982bf12cdd3484c6>:0)
UnityEngine.UIElements.UIEventRegistration.UpdateSchedulers () (at <9d7fc877145d4138982bf12cdd3484c6>:0)
UnityEditor.RetainedMode.UpdateSchedulers () (at <f90f2d9cb28d4393afc1338e6af635e0>:0)

I’ve also been getting this error. I believe that it, along with another error has to do with when a public or serialized variable “disappears” while the editor is trying to present it. In particular I’m noticing it with a list I’m using, which is filled up on game start. When I exit play mode with the object containing this list open in the inspector, it seems like the list empties. This causes the error to be spammed in my console until I switch to inspect a different object in my hierarchy.

I believe my other issue, an occasional error reading “ObjectDisposedException: SerializedProperty Tasks.Array.data[1] has disappeared!” is also related to this. it comes up when I remove an item from the list during gameplay while I have the game object open in the inspector. My suspicion is that since the serialized list changed, the unity inspector is just running into difficulty with presenting this change.

Both of these issues seem to have been resolved by refactoring my list to be private. I’ll post back on this forum if I run into either of them again. But in the meantime it seems like these issues aren’t especially destructive towards internal gameplay (just the editor), and might be able to be fixed by deserializing them or making them private

tl;dr: I’ve found this issue (along with another) tends to occur while serialized data structures (in my case a List) have items removed while visible in the inspector

1 Like

Same Problem on 2022.3.10f1

How to replicate:

using System;
using System.Collections.Generic;
using UnityEngine;

[Serializable]
public class Data
{
    public int number;
}
public class BugTest : MonoBehaviour
{
    [SerializeField] List<Data> data;
}

Stick this into a gameobject. Press Play, Select gameobject, Add a Data Element, while still selecting the game object, stop the playmode.

Script in editor ends up looking like first image while it should look like second image

happens with both Data[ ] and List as well as with Data being a struct.


1 Like

pasting the error

NullReferenceException: SerializedObject of SerializedProperty has been Disposed.
UnityEditor.SerializedProperty.get_intValue () (at /Users/bokken/build/output/unity/unity/Editor/Mono/SerializedProperty.bindings.cs:996)
UnityEditor.UIElements.Bindings.ListViewSerializedObjectBinding.UnbindListViewItem (UnityEngine.UIElements.VisualElement ve, System.Int32 index) (at /Users/bokken/build/output/unity/unity/ModuleOverrides/com.unity.ui/Editor/Bindings/ListViewBindings.cs:201)
UnityEngine.UIElements.ListViewController.UnbindItem (UnityEngine.UIElements.VisualElement element, System.Int32 index) (at /Users/bokken/build/output/unity/unity/ModuleOverrides/com.unity.ui/Core/Collections/Controllers/ListViewController.cs:47)
UnityEngine.UIElements.CollectionViewController.InvokeUnbindItem (UnityEngine.UIElements.ReusableCollectionItem reusableItem, System.Int32 index) (at /Users/bokken/build/output/unity/unity/ModuleOverrides/com.unity.ui/Core/Collections/Controllers/CollectionViewController.cs:174)
UnityEngine.UIElements.VerticalVirtualizationController`1[T].ReleaseItem (System.Int32 activeItemsIndex) (at /Users/bokken/build/output/unity/unity/ModuleOverrides/com.unity.ui/Core/Collections/Virtualization/VerticalVirtualizationController.cs:382)
UnityEngine.UIElements.DynamicHeightVirtualizationController`1[T].ReleaseItem (System.Int32 activeItemsIndex) (at /Users/bokken/build/output/unity/unity/ModuleOverrides/com.unity.ui/Core/Collections/Virtualization/DynamicHeightVirtualizationController.cs:994)
UnityEngine.UIElements.VerticalVirtualizationController`1[T].Refresh (System.Boolean rebuild) (at /Users/bokken/build/output/unity/unity/ModuleOverrides/com.unity.ui/Core/Collections/Virtualization/VerticalVirtualizationController.cs:105)
UnityEngine.UIElements.DynamicHeightVirtualizationController`1[T].Refresh (System.Boolean rebuild) (at /Users/bokken/build/output/unity/unity/ModuleOverrides/com.unity.ui/Core/Collections/Virtualization/DynamicHeightVirtualizationController.cs:162)
UnityEngine.UIElements.BaseVerticalCollectionView.RefreshItems () (at /Users/bokken/build/output/unity/unity/ModuleOverrides/com.unity.ui/Core/Controls/BaseVerticalCollectionView.cs:900)
UnityEngine.UIElements.CollectionViewController.set_itemsSource (System.Collections.IList value) (at /Users/bokken/build/output/unity/unity/ModuleOverrides/com.unity.ui/Core/Collections/Controllers/CollectionViewController.cs:44)
UnityEngine.UIElements.BaseVerticalCollectionView.set_itemsSource (System.Collections.IList value) (at /Users/bokken/build/output/unity/unity/ModuleOverrides/com.unity.ui/Core/Controls/BaseVerticalCollectionView.cs:253)
UnityEditor.UIElements.Bindings.ListViewSerializedObjectBinding.ClearListView () (at /Users/bokken/build/output/unity/unity/ModuleOverrides/com.unity.ui/Editor/Bindings/ListViewBindings.cs:132)
UnityEditor.UIElements.Bindings.ListViewSerializedObjectBinding.Release () (at /Users/bokken/build/output/unity/unity/ModuleOverrides/com.unity.ui/Editor/Bindings/ListViewBindings.cs:292)
UnityEditor.UIElements.Bindings.SerializedObjectBindingContext.RemoveBinding (UnityEngine.UIElements.IBindable bindable, System.Boolean forceRemove) (at /Users/bokken/build/output/unity/unity/ModuleOverrides/com.unity.ui/Editor/Bindings/BindingExtensions.cs:468)
UnityEditor.UIElements.Bindings.SerializedObjectBindingContext.Unbind (UnityEngine.UIElements.VisualElement element) (at /Users/bokken/build/output/unity/unity/ModuleOverrides/com.unity.ui/Editor/Bindings/BindingExtensions.cs:70)
UnityEditor.UIElements.Bindings.DefaultSerializedObjectBindingImplementation.UnbindTree (UnityEngine.UIElements.VisualElement element) (at /Users/bokken/build/output/unity/unity/ModuleOverrides/com.unity.ui/Editor/Bindings/BindingExtensions.cs:838)
UnityEditor.UIElements.Bindings.DefaultSerializedObjectBindingImplementation.Unbind (UnityEngine.UIElements.VisualElement element) (at /Users/bokken/build/output/unity/unity/ModuleOverrides/com.unity.ui/Editor/Bindings/BindingExtensions.cs:822)
UnityEditor.UIElements.BindingExtensions.Unbind (UnityEngine.UIElements.VisualElement element) (at /Users/bokken/build/output/unity/unity/Editor/Mono/UIElements/Bindings/BindingsInterface.cs:65)
UnityEditor.UIElements.PropertyField.Reset (UnityEditor.SerializedProperty newProperty) (at /Users/bokken/build/output/unity/unity/Editor/Mono/UIElements/Controls/PropertyField.cs:244)
UnityEditor.UIElements.PropertyField.Reset (UnityEditor.UIElements.SerializedPropertyBindEvent evt) (at /Users/bokken/build/output/unity/unity/Editor/Mono/UIElements/Controls/PropertyField.cs:347)
UnityEditor.UIElements.PropertyField.ExecuteDefaultActionAtTarget (UnityEngine.UIElements.EventBase evt) (at /Users/bokken/build/output/unity/unity/Editor/Mono/UIElements/Controls/PropertyField.cs:182)
UnityEngine.UIElements.CallbackEventHandler.HandleEvent (UnityEngine.UIElements.EventBase evt) (at /Users/bokken/build/output/unity/unity/ModuleOverrides/com.unity.ui/Core/Events/EventHandler.cs:281)
UnityEngine.UIElements.CallbackEventHandler.HandleEventAtCurrentTargetAndPhase (UnityEngine.UIElements.EventBase evt) (at

Unity Issue Tracker - NullReferenceException is flooded when exiting Play Mode while Inspector is displaying a list whose contents are generated at runtime (unity3d.com)

2 Likes

Still not fixed ._. It occurs when updating an array while its shown in inspector.

Same here. Does anyone working on this issue?..

In my case, one of my component with a list of serializable classes kept throwing the serialized property has been disposed.

The error only occurs when I have the list expanded and if I reload the inspector, it goes away. (I guess the Serialized Object ref gets collected by the GC properly).

Surprisingly, creating an editor and calling serializedObject.ApplyModifiedProperties on the serialized object pretty much stopped the error.

[CustomEditor(typeof(Foo))]
public class FooEditor : Editor
{
    public override void OnInspectorGUI()
    {
        this.serializedObject.ApplyModifiedProperties();
        base.OnInspectorGUI();
    }
}

Maybe this will help someone!

2 Likes