NullReferenceException: Object reference not set to an instance of an object

Mushrooms Labs Q&ACategory: Curved Poly Shape EditorNullReferenceException: Object reference not set to an instance of an object
MaryTwist asked 3 years ago

Hello.
Curved Poly Editor Window raises a few exceptions when I trying to open it.
Log:

NullReferenceException: Object reference not set to an instance of an object
MLab.CurvedPoly.eHPN.UnityControl.WindowsLoader.Init () (at <6dd6fa46a2354ed0bf91559823758ea8>:0)

NullReferenceException: Object reference not set to an instance of an object
MLab.CommonTools.InSceneMenu.BuildButtonStyle () (at :0)
MLab.CommonTools.InSceneMenu.AutoHelpButton (System.Int32 width, MLab.CommonTools.InSceneMenu+DrawButtonAction action, System.Int32 y) (at :0)
MLab.CurvedPoly.eHPN.UnityControl.CurvedPolyEditorWindow.OnGUI () (at <6dd6fa46a2354ed0bf91559823758ea8>:0)
UnityEditor.HostView.InvokeOnGUI (UnityEngine.Rect onGUIPosition, UnityEngine.Rect viewRect) (at <1e441e8684a14fe4b8f8a926d91afc3a>:0)
UnityEditor.DockArea.DrawView (UnityEngine.Rect viewRect, UnityEngine.Rect dockAreaRect) (at <1e441e8684a14fe4b8f8a926d91afc3a>:0)
UnityEditor.DockArea.OldOnGUI () (at <1e441e8684a14fe4b8f8a926d91afc3a>: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 <3cdf672c21b849dea215f9c9aff21f77>:0)
UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr, Boolean&)

… and so on. Editor window displayed empty.
Unity versions:
2019.4.17f1
2020.2.1f1
 

1 Answers
Alessandro MartinelliAlessandro Martinelli Staff answered 3 years ago

Hello MaryTwist.
I’m really sorry this issue occured to you. This is a very uncommon issue that happened to me last time 5 months ago I think.
Basically: Curved Poly failed to load some of its assets (the ones found in CurvedPoly/Editor/UI) and because of this it cannot show the Editor correctly. I think you should have a warning in your inspector about this, saying “We Couldn’t load the files required to build the Scene View Editor”.
I can’t know if that is your case, but for instance this may happen when Curved Poly Maker is imported in a project that have a previously imported version of Curved Poly – Shape Editor. What we need to do in this case is simply to force a correct reload of that assets, then the Editor Window should work good.
Here a few things you should try to overcome this:

  • Close and reopen the project. It should work.
  • Reimport the Assets from the Unity Editor: in the Project panel, Right-Click either on ‘CurvedPoly’ folder or on ‘CurvedPoly/Editor’ folder, to show the popup menu, and find ‘Reimport’. This will Reimport all the Editor assets.
  • Reimport the Assets from the Asset Store: maybe you have some missing file, maybe something went wrong during download. In that case you can just re-import them from the asset store.
  • Create a fresh-new project: I don’t know if that an option for you, but I can confirm I opened CPMaker on 2020.2.1f1 and on 2019.4.17f1 on a fresh-new project without any issue. Everything is working fine.
  • (After any of the previous) Reload the Windows: close any Curved Poly Window from the project (C.P.Editor-C.P.Inspector-LoDs Preview-Help I mean the 4 ones you can open from the Inspector), then open them again to get them reloaded.

 
Furthermore. I was trying to emulate the issue and I managed to do so by importing CP-Maker on 2020.2.1f1 (was working), then i switched to 2019.4.17f1 (still working) then I removed the Curved Poly Folder and re-imported Curved Poly again and (only) so I was able to see your same thing. Then, in order to fix i simply closed and reopened the project, as suggested. 
So, I trust it works for you too.