Search Unity

Question Unity Editor Null Reference Exception

Discussion in 'Editor & General Support' started by MerlinG2, Oct 9, 2020.

  1. MerlinG2

    MerlinG2

    Joined:
    Jun 17, 2020
    Posts:
    44
    When ever I try to use the animation window or play test my game inside of unity, this error appears and I don't know how to get rid of it. I've tried creating a new project and porting over all of my assets but it wont stop. One other thing to note it that this only started when I downloaded Unity Editor 2019.4.12f1.

    Any help would be greatly appreciated, thanks.

    Here's the error:

    NullReferenceException: Object reference not set to an instance of an object
    UnityEditor.EditorWindow.RefreshStylesAfterExternalEvent () (at <e6e2fa0a47414cd2ac33237924761b45>:0)
    UnityEditor.AnimationMode.StartAnimationRecording () (at <e6e2fa0a47414cd2ac33237924761b45>:0)
    UnityEditorInternal.AnimationWindowControl.StartRecording () (at <e6e2fa0a47414cd2ac33237924761b45>:0)
    UnityEditorInternal.AnimationWindowControl.StartRecording (UnityEngine.Object targetObject) (at <e6e2fa0a47414cd2ac33237924761b45>:0)
    UnityEditorInternal.AnimationWindowState.StartRecording () (at <e6e2fa0a47414cd2ac33237924761b45>:0)
    UnityEditor.AnimEditor.RecordButtonOnGUI () (at <e6e2fa0a47414cd2ac33237924761b45>:0)
    UnityEditor.AnimEditor.PlayControlsOnGUI () (at <e6e2fa0a47414cd2ac33237924761b45>:0)
    UnityEditor.AnimEditor.OnAnimEditorGUI (UnityEditor.EditorWindow parent, UnityEngine.Rect position) (at <e6e2fa0a47414cd2ac33237924761b45>:0)
    UnityEditor.AnimationWindow.OnGUI () (at <e6e2fa0a47414cd2ac33237924761b45>:0)
    System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at <9577ac7a62ef43179789031239ba8798>:0)
    Rethrow as TargetInvocationException: Exception has been thrown by the target of an invocation.
    System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at <9577ac7a62ef43179789031239ba8798>:0)
    System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) (at <9577ac7a62ef43179789031239ba8798>:0)
    UnityEditor.HostView.Invoke (System.String methodName, System.Object obj) (at <e6e2fa0a47414cd2ac33237924761b45>:0)
    UnityEditor.HostView.Invoke (System.String methodName) (at <e6e2fa0a47414cd2ac33237924761b45>:0)
    UnityEditor.HostView.InvokeOnGUI (UnityEngine.Rect onGUIPosition, UnityEngine.Rect viewRect) (at <e6e2fa0a47414cd2ac33237924761b45>:0)
    UnityEditor.DockArea.DrawView (UnityEngine.Rect viewRect, UnityEngine.Rect dockAreaRect) (at <e6e2fa0a47414cd2ac33237924761b45>:0)
    UnityEditor.DockArea.OldOnGUI () (at <e6e2fa0a47414cd2ac33237924761b45>:0)
    UnityEngine.UIElements.IMGUIContainer.DoOnGUI (UnityEngine.Event evt, UnityEngine.Matrix4x4 parentTransform, UnityEngine.Rect clippingRect, System.Boolean isComputingLayout, UnityEngine.Rect layoutSize, System.Action onGUIHandler, System.Boolean canAffectFocus) (at <356f1ddb1d524ad59c7a2c95775bb38e>:0)
    UnityEngine.UIElements.IMGUIContainer.HandleIMGUIEvent (UnityEngine.Event e, UnityEngine.Matrix4x4 worldTransform, UnityEngine.Rect clippingRect, System.Action onGUIHandler, System.Boolean canAffectFocus) (at <356f1ddb1d524ad59c7a2c95775bb38e>:0)
    UnityEngine.UIElements.IMGUIContainer.HandleIMGUIEvent (UnityEngine.Event e, System.Action onGUIHandler, System.Boolean canAffectFocus) (at <356f1ddb1d524ad59c7a2c95775bb38e>:0)
    UnityEngine.UIElements.IMGUIContainer.HandleIMGUIEvent (UnityEngine.Event e, System.Boolean canAffectFocus) (at <356f1ddb1d524ad59c7a2c95775bb38e>:0)
    UnityEngine.UIElements.IMGUIContainer.SendEventToIMGUI (UnityEngine.UIElements.EventBase evt, System.Boolean canAffectFocus) (at <356f1ddb1d524ad59c7a2c95775bb38e>:0)
    UnityEngine.UIElements.IMGUIContainer.HandleEvent (UnityEngine.UIElements.EventBase evt) (at <356f1ddb1d524ad59c7a2c95775bb38e>:0)
    UnityEngine.UIElements.CallbackEventHandler.HandleEventAtTargetPhase (UnityEngine.UIElements.EventBase evt) (at <356f1ddb1d524ad59c7a2c95775bb38e>:0)
    UnityEngine.UIElements.MouseCaptureDispatchingStrategy.DispatchEvent (UnityEngine.UIElements.EventBase evt, UnityEngine.UIElements.IPanel panel) (at <356f1ddb1d524ad59c7a2c95775bb38e>:0)
    UnityEngine.UIElements.EventDispatcher.ApplyDispatchingStrategies (UnityEngine.UIElements.EventBase evt, UnityEngine.UIElements.IPanel panel, System.Boolean imguiEventIsInitiallyUsed) (at <356f1ddb1d524ad59c7a2c95775bb38e>:0)
    UnityEngine.UIElements.EventDispatcher.ProcessEvent (UnityEngine.UIElements.EventBase evt, UnityEngine.UIElements.IPanel panel) (at <356f1ddb1d524ad59c7a2c95775bb38e>:0)
    UnityEngine.UIElements.EventDispatcher.ProcessEventQueue () (at <356f1ddb1d524ad59c7a2c95775bb38e>:0)
    UnityEngine.UIElements.EventDispatcher.OpenGate () (at <356f1ddb1d524ad59c7a2c95775bb38e>:0)
    UnityEngine.UIElements.EventDispatcherGate.Dispose () (at <356f1ddb1d524ad59c7a2c95775bb38e>:0)
    UnityEngine.UIElements.EventDispatcher.ProcessEvent (UnityEngine.UIElements.EventBase evt, UnityEngine.UIElements.IPanel panel) (at <356f1ddb1d524ad59c7a2c95775bb38e>:0)
    UnityEngine.UIElements.EventDispatcher.Dispatch (UnityEngine.UIElements.EventBase evt, UnityEngine.UIElements.IPanel panel, UnityEngine.UIElements.DispatchMode dispatchMode) (at <356f1ddb1d524ad59c7a2c95775bb38e>:0)
    UnityEngine.UIElements.BaseVisualElementPanel.SendEvent (UnityEngine.UIElements.EventBase e, UnityEngine.UIElements.DispatchMode dispatchMode) (at <356f1ddb1d524ad59c7a2c95775bb38e>:0)
    UnityEngine.UIElements.UIElementsUtility.DoDispatch (UnityEngine.UIElements.BaseVisualElementPanel panel) (at <356f1ddb1d524ad59c7a2c95775bb38e>:0)
    UnityEngine.UIElements.UIElementsUtility.ProcessEvent (System.Int32 instanceID, System.IntPtr nativeEventPtr) (at <356f1ddb1d524ad59c7a2c95775bb38e>:0)
    UnityEngine.GUIUtility.ProcessEvent (System.Int32 instanceID, System.IntPtr nativeEventPtr) (at <819de1aa368e45faa4f78e26c97c62b0>:0)
     
  2. spalamas

    spalamas

    Joined:
    Aug 30, 2019
    Posts:
    26
    I have exaclty the same problem when I try to record an animation of an object inside a timeline and it did indeed started when I upgrated to Unity 2019.4.12f1 .
     
  3. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,735
    Try refreshing / updating your packages, and also try restoring the editor window layouts... it smells windows layout related with that "styles" comment at the top, but I could be wrong. Another thing to try is Reimport-All
     
    mmcveigh33, Ali_Jaras and spalamas like this.
  4. spalamas

    spalamas

    Joined:
    Aug 30, 2019
    Posts:
    26
    Thanks a lot man! That solved the problem. It was an editor issue indeed. I restored the editor layout to default and did my setup again and now it works. I also noticed that when I opened my project I got a message that the editor layout could not be fully loaded as an editor window is not available in my project. I ignored it until I read your answer so that might be causing the problem.
     
    ChronoWalker likes this.
  5. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,735
    This can happen for a variety of reasons. One is that you have a compiler error on startup, or else you changed the name (or removed) an editor window class, a class of which a window was open, so Unity can't create it now and complains bitterly.

    Glad you're up and going again.
     
  6. HuldaGnodima

    HuldaGnodima

    Joined:
    Oct 10, 2016
    Posts:
    110
    Just want to say I'm having the same problem.
    I'm also on Unity 2019.4.12f1 (I think it may have started when I upgraded to this version but can't recall the exact date it first happened)

    I have so far tried the following things to fix the error-message:
    1.) Reloaded the layout to default,
    2.) Tried restarting Unity multiple times.
    3.) Tried Reimport All (via Assets -> Reimport all)
    4.) Gone through each package I have in my project (via Package Manager) to make sure all are at latest update.
    Still the problem remains, I get the following error-message when I hit the record-button:

    NullReferenceException: Object reference not set to an instance of an object
    UnityEditor.EditorWindow.RefreshStylesAfterExternalEvent () (at <e6e2fa0a47414cd2ac33237924761b45>:0)

    Spalamas would you mind detailing the exact steps you took to get rid of this bug?
    Then I may try it and see if it also works for me. Thank you so much in advance.
     
  7. spalamas

    spalamas

    Joined:
    Aug 30, 2019
    Posts:
    26
    Hello there. My problem was solved when I selected Window->Layout->Default so Unity editor reverted to the default layout. Then I re-adjusted the windows as I prefer. The record button started to work.!

    However after working for a while the problem reoccured , I can't find under what conditions! I switched again to the default layout and then readjusted the windows to suit my preferences and the record button works again. This time I saved my layout so when the problem reoccures and I switch to the default it will be easy to bring back my layout.
     
  8. HuldaGnodima

    HuldaGnodima

    Joined:
    Oct 10, 2016
    Posts:
    110
    Thanks for describing your steps! I'm sure other people will find this thread with the same problem, and perhaps your fix will help them.
    Yes, the problem reoccurs for me as well even after I've put the Layout to Default.

    I upgraded to Unity LTS Release 2019.4.13f1 yesterday and the error-messages (after pressing the animation record button) persisted.
    I tried loading a custom Layout I had saved previously (not the default-layout) and then finally the error-messages stopped.
    It leads me to think/suspect this issue may be somehow related to the Default Unity Layout?

    Anyhow, keep us posted if you figure something else out! :)
     
  9. spalamas

    spalamas

    Joined:
    Aug 30, 2019
    Posts:
    26
    Meanwhile by installing 2019.4.13 the problem has not dissapeared. Whenever I open Unity the recording does not work and I have to switch layouts to make it work. PLUS since I installed 2019.4.13 when I double click on a script component on the inspector it won't open on Visual Studio! Even the circle icon next to the script name which indicates the location of the file does not work. I have to manualy locate the scipt on the project manager and double click it there to open on Visual Studio. I searched and ocasionaly other users had the same problem in older versions but none of the solutions they proposed worked for me. Seems like every new version introduces a new problem :)
     
  10. HuldaGnodima

    HuldaGnodima

    Joined:
    Oct 10, 2016
    Posts:
    110
    Thank you for describing how it works for you in such detail. I have the very same issues with the new version (2019.4.13) that you describe! I wonder if maybe one of us should file an official bug-report?
     
  11. Ali_Jaras

    Ali_Jaras

    Joined:
    May 3, 2021
    Posts:
    1
    Lots of thanks Man I have restored the editor layout and the error is gone you have made my day :)
    thanks
     
    Kurt-Dekker likes this.
  12. zakolebali

    zakolebali

    Joined:
    Dec 17, 2021
    Posts:
    4
    Had a same problem with 2020.3.26f1 and 2020.3.27f1.
    Switching layouts works!
    Thanks guys!
     
  13. Gordon_G

    Gordon_G

    Joined:
    Jun 4, 2013
    Posts:
    372
    Just wanted to add restoring layouts worked for me. I had a custom layout I created in Unity 2020, and I upgraded one specific project to 2021 and I started getting the error.. I think that had something to do with it because the other projects that I have that are still v2020 do not generate this error. It was only the one I upgraded.