NullReferenceException: SerializedObject of SerializedProperty has been Disposed.

Also this error seems unity itself, I can’t debug, cuz not my code’s problem.

This error occurs continuously even after exit game play mode.

using 2022.2.17f1

error

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

2 Likes

That issue has started for me recently as well. That error repeats continuously any time I save my scripts, or when I start game testing. It continues after I stop the game. It looks like it’s happening whenever I’m viewing the inspector on my main canvas which has most of my main scripts attached to it. When I click on another object it stops, then I can go back to my main canvas. After saving or starting the game the issue starts again. It first prints this error:

ArgumentNullException: Value cannot be null.
Parameter name: _unity_self
UnityEditor.UIElements.Bindings.SerializedObjectList.get_Count () (at /Users/bokken/build/output/unity/unity/ModuleOverrides/com.unity.ui/Editor/Bindings/ListViewBindings.cs:453)

Then repeats this error endlessly:

NullReferenceException: SerializedObject of SerializedProperty has been Disposed.
UnityEditor.SerializedProperty.get_objectReferenceInstanceIDValue () (at /Users/bokken/build/output/unity/unity/Editor/Mono/SerializedProperty.bindings.cs:1413)
UnityEditor.EditorGUIUtility.ObjectContent (UnityEngine.Object obj, System.Type type, UnityEditor.SerializedProperty property, UnityEditor.EditorGUI+ObjectFieldValidator validator) (at /Users/bokken/build/output/unity/unity/Editor/Mono/EditorGUIUtility.cs:1003)
UnityEditor.UIElements.ObjectField+ObjectFieldDisplay.Update () (at /Users/bokken/build/output/unity/unity/Editor/Mono/UIElements/Controls/ObjectField.cs:137)
UnityEditor.UIElements.ObjectField.UpdateDisplay () (at /Users/bokken/build/output/unity/unity/Editor/Mono/UIElements/Controls/ObjectField.cs:90)
UnityEngine.UIElements.VisualElement+SimpleScheduledItem.PerformTimerUpdate (UnityEngine.UIElements.TimerState state) (at /Users/bokken/build/output/unity/unity/ModuleOverrides/com.unity.ui/Core/VisualElementScheduler.cs:346)
UnityEngine.UIElements.TimerEventScheduler.UpdateScheduledEvents () (at /Users/bokken/build/output/unity/unity/ModuleOverrides/com.unity.ui/Core/Scheduler.cs:362)
UnityEngine.UIElements.UIElementsUtility.UnityEngine.UIElements.IUIElementsUtility.UpdateSchedulers () (at /Users/bokken/build/output/unity/unity/ModuleOverrides/com.unity.ui/Core/UIElementsUtility.cs:253)
UnityEngine.UIElements.UIEventRegistration.UpdateSchedulers () (at /Users/bokken/build/output/unity/unity/ModuleOverrides/com.unity.ui/Core/UIElementsUtility.cs:105)
UnityEditor.RetainedMode.UpdateSchedulers () (at /Users/bokken/build/output/unity/unity/ModuleOverrides/com.unity.ui/Editor/RetainedMode.cs:55)

so this started occur rather newer version of unity. never experienced before.

I think there’s a bug in a version of the Version Control package that causes this. Removing or updating the package should fix it.

I don’t use any version control package. But error occurs.

Unity’s Version Control package is included by default in new projects, so you will likely need to remove it via the package manager.

1 Like

Have the same issue on 2022.2.17.
Can you say please is it fixed in newer version of Unity? Or may be you found other solution?

I don’t find any solution yet. Unity should do it. And I am using newest(2.21) version, but it seems not so much occurs now, but can’t sure why. I did [spiney199]'s method above, maybe cus of this.

In my project Unity’s Version Control has never been included.
Error happens literally after each Play Mode enter and exit if object with several custom editors selected.
In editor mode it disappearing only after scripts recompilation.
In enter play mode it stops after new scene loaded and I change selection in inspector.

Did you submit bug report?

Nope… I don’t have time…

Hello, I just had the same issue in 2022.3.6f1.

It was caused by a [SerializeField][Range(x,x)] variable which had too big of a name, so the range slider overlapped with the name in the editor.

Renaming to a shorter name fixed the overlapping, and I stopped getting the error.

I would advise checking for any weird UI thing happening in your serialized fields (in the editor), and fixing them if there are any.
I hope it helps.

1 Like

I updated to 2022 LTS (currently version 2022.3.7f1) from 2021 LTS today and ran into this issue. I was able to track it down and reproduce it. It’s possible there are multiple causes, but for me it occurs when you exit play mode while the inspector is displaying a list whose contents are generated at runtime. The list has to be in the expanded state when exiting play mode for it to occur, if it is collapsed, the error won’t occur. I noticed that it requires two such lists to be in the inspector (only one of which needs to be open) to result in the infinitely repeating error message. If you only have one such list, it will display the error message only once.

To workaround the issue, you can collapse any such lists in the inspector or select an item in the hierarchy that does not cause any such lists to be displayed in the inspector before exiting play mode. If you forget to do this and the infinitely scrolling error message occurs, you can select another item in the hierarchy that doesn’t display such a list and then enter and exit play mode again and it should stop.

I typed up and sent in a bug report, so hopefully it will be addressed in a future update.

EDIT: It’s now on the issue tracker: Unity Issue Tracker - NullReferenceException is flooded when exiting Play Mode while Inspector is displaying a list whose contents are generated at runtime

15 Likes

update Unity’s Version Control to latest version fix my problem, unity 2022.3.7f1

I haven’t found a proper solution yet, but I have tracked down what causes the issue for me.

I have some prefabs in the scene which inherits from a shared abstract class, which has several [SerializeField] variables.

If I click Play In Editor and then have one of those prefabs selected in the hierarchy when I stop playing, then the error happens. If I do not have any of those prefabs selected when I stop playing, then the issue goes away.

So whatever is happening, I guess, is that the inspector does not have enough time to initialize one or more of the fields on the prefab if it is highlighted during the inspector refresh (possibly due to those fields being part of an abstract class?). Seems like some weird GUI execution order issue.

I’ve just started getting this error when I try to add items to a SerializeField list in the inspector. When I click the plus sign to add an element, I get the error and the whole list disappears from the inspector. Clicking Undo brings it back, but it takes many attempts of clicking plus and undo until I get the number of fields I want. Once I have the fields, I can drag assets into them with no further issue, and everything seems to work properly in Play mode. The error in the console is like 50 lines long, pointing to various UnityEditor.UIElements… things.

This only started happening since upgrading from 2022.3.9 to 2022.3.10 the other day.

1 Like

Had the same error. For me the reason was that I was initializing a List right away and not in Awake or Start.

public class SomeClass : MonoBehaviour
{
    public List<GameObject> someList= new List<GameObject>;
}
3 Likes

Thanks! I was doing the same–I don’t initialize it in Awake or Start because I want to populate the list in the inspector. Anyway, I tried changing the format to ‘public List someList;’ (without the ‘= new List’ part) and that seems to work just as well, so hopefully that clears up the error.

Work for me! Thanks you!

I had the similar error.
I thought it was happening because I started to use play mode save asset.

In fact, it’s related to that asset. I instantiate prefabs in the play mode and then exit. When I exit, it instantiates prefabs in the edit mode. I guess it happens too quickly that unity doesn’t have time to set its values.

My workaound is, when exiting play mode, not to keep prefabs generated at runtime selected. If inspector doesn’t show object properties, it doesn’t throw error in edit mode.

It took me understand a good amount of time.
I wish I looked here way before

This bug now appears to be fixed in the latest versions!