Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by demonpants · Jan 26, 2013 at 06:52 PM · editorbugnullreferenceexceptionunity4customeditor

NullReferenceException when looking at target in an Editor class (CustomEditor)

Hi. I have some code that worked fine in Unity 3, and now constantly throws Exceptions in Unity 4. I suspect this is a bug.

If I even look at the value of target in my CustomEditor class, then a NRE happens, which shouldn't happen. It appears to go through a broken accessor in Unity's internal code.

The specific error is:

 NullReferenceException: Object reference not set to an instance of an object
 UnityEditor.Editor.get_referenceTargetIndex ()
 UnityEditor.Editor.get_target ()
 LDLevelObjectEditor.OnEnable () (at Assets/Editor/LDLevelObjectEditor.cs:63)

Line 63 in LDLevelObjectEditor is in OnEnable():

 //line 63 is the one directly below
 LDLevelObject o = target as LDLevelObject;
     
 if ( o == null )
 {
     return;
 }

You can see I even escape out if target does not exist for some reason. But the very nature of trying to access the target causes a NRE. I'm thinking it's trying to get the target from a null GameObject, but that shouldn't be possible if Unity is working correctly.

Also it's worth noting that this happens during gameplay, which should never be the case since this is an Editor class.

Anybody encountered this and maybe know of a fix?

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image dkozar · May 25, 2013 at 03:03 PM 0
Share

Have you solve it yet?

I'm having the same problem (Windows, Unity 3.5.6f6).

It happens after the assembly reload (while in Play mode), and there seems the Inspector renders nothing, although the selection (in the Hierarchy) window remains after the reload.

The exception is being continuously thrown, until I select another object in the hierarchy window - then it stops (and the Inspector is being redrawn properly).

Also, I noticed that this doesn't happen always, but in a 90% of cases.

And yes, it is related to "reading" the target property of the Editor class.

Thanks for the answer!

2 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by dkozar · May 25, 2013 at 04:29 PM

Just found out that it happens ONLY when recompiling my custom assembly containing the editor code.

Somehow I managed to get a proper error message, which was:

"Instance of StageEditor couldn't be created because there is no script with that name."

("StageEditor" is the name of my custom editor)

This doesn't happen if I don't touch the editor code, but only changing scripts that have nothing to do with the editor (their change doesn't require the Custom editor assembly rebuild). The assembly reloads normally, the Inspector renders OK, and there's no the "target" problem.

Guess I could live with that (final users won't see this error) :)

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image demonpants · May 25, 2013 at 09:40 PM 0
Share

I got this to go away, but I honestly can't recall how. Hmmm...

avatar image
0

Answer by Hexane · Aug 12, 2021 at 03:12 PM

I just want to add that this bug is still happening in Unity 2020.3.15.F2 and this is the top search result for me. It went away after restarting the Unity Editor. ✌

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

11 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Unity Inspector Interface 5 Answers

Unity 5 editor flickering/glitchy (examples inside) 3 Answers

Strange graphical bug in Editor GUI 1 Answer

DrawDefaultInspector crash 1 Answer

What is unity4 for AssetDatabase.GetAllAssetPaths? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges