Whenever I press the Unity Editor's play button, I get this error:

NullReferenceException: Object reference not set to an instance of an object
UnityEditor.PropertyEditor.DrawEditors (UnityEditor.Editor[] editors) (at <4f969f18b6984883abf0f762caf9325d>:0)
UnityEditor.PropertyEditor.RebuildContentsContainers () (at <4f969f18b6984883abf0f762caf9325d>:0)
UnityEditor.InspectorWindow.RedrawFromNative () (at <4f969f18b6984883abf0f762caf9325d>:0)

Notes:

  • I still can play the scene, even with the error showing in the Console.
  • The error only pops up when I press the play button.
  • The error is clearable.

I think the error started about the time I played with the Canvas’s component Canvas Scaler I’M NOT SURE, but I undo all the changes, but the error still persists.

I was having a similiar issue! I had 2 inspectors opened in my project! Closing one of them made the error to stop (Using Unity 2020.3.5f1). Not sure if closing the inspector was the solution but it was the last thing I tried to make the error go away!

Window > Layouts > Default

Worked for me.

Close all duplicate screens/Panels on the Unity editor and restart unity error will go away

Window → Layouts → Reset all layouts
(Unity 2020.3.27f)
It helped me

Same problem here but it only went away by closing my inspector tab and re-opening it again.

Thanks anyway everyone!

Restarting both visual studio and unity worked for me. I did not have two inspector windows open or anything like that. Hope this saves someone’s time. Simple restart.

That worked, I try to keep multi-tabs open from other areas, but once I closed my extra inspector I could demo the game again. Thank you!

-ONO

As others have pointed out, having more than 1 instance of a menu in the editor can make that error appear, but it can also be due to the nature of Unity not being able to update the content of inactive tabs when you open the editor.


Just in case, make sure you switch to all tabs opened once after the error starts appearing. Chances are high that the error appears because one of the hidden tab tries to reach an old reference from a previous access that is now closed. (This is often the case of a 2nd inspector or a locked inspector menu which is why closing the 2nd one often does the trick.)


If you select the tab of an hidden/unfocused menu and the content of that menu is blank, but has the header of a selection, you have found the culprit. (For example, if an inspector has an icon and a name at the top, but display no component at all, that’s an example of when an Inspector UI attempt to reach a NULL reference.)


The solution: Either close any hidden/unfocused menus or select them and make sure their current selection is viable. (So, for example, make sure all Inspector has a proper selection, the Animator has a proper animation selected or none, the Controls (Input Actions) refers to the actual inputs action of the project, the Audio Mixer is properly selected, etc.) This error can also happen if you got a custom menu opened and it attempts to access some missing/unavailable files in a project. (As long as any UI elements in the editor attempt to access a NULL/unavailable reference, it will returns that error when you press Play.)

Don’t select any gameobject in the hierarchy while playing make sure nothing is selected.

Happening to me in 2022.3.49 and I do not have duplicate menu tabs open.

UnityEditor.AudioClipInspector.OnPreviewGUI (UnityEngine.Rect r, UnityEngine.GUIStyle background) (at <0e74aaecc5d24ba79f82222a4901f731>:0)
UnityEditor.Editor.OnInteractivePreviewGUI (UnityEngine.Rect r, UnityEngine.GUIStyle background) (at <0e74aaecc5d24ba79f82222a4901f731>:0)
UnityEditor.ObjectPreview.DrawPreview (UnityEditor.IPreviewable defaultPreview, UnityEngine.Rect previewArea, UnityEngine.Object[] targets) (at <0e74aaecc5d24ba79f82222a4901f731>:0)

What I did that solves the problem is I converted the preview window to floating. Then I re-docked it in the bottom of the inspector. Error is gone (so far!).