Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 Eastwing · Dec 11, 2014 at 07:57 AM · componentcustom editorrepaint

Is it way to force redraw all components of GO in inspector?

Subj. I have some script manages adding/removing others scripts on its GameObject. But when I remove some component, I got error:

 MissingReferenceException: The object of type 'script_you_just_remove' has been destroyed but you are still trying to access it.
 Your script should either check if it is null or you should not destroy the object.

I belive, it's because Unity Inspector "don't know" that removed component does not exists anymore and try to draw it at current iteration. So, I guess I must somehow repaint all components. Is there any way to do it? Thanks.

Comment
Add comment · Show 4
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 GameVortex · Dec 11, 2014 at 08:30 AM 0
Share

That is most likely not the issue, Unity knows the component has been destroyed because it is Unity that destroys it when you call the Destroy function.

If you check the entire error message it gives you a script and a line number where the error occurs. This is most likely in one of your scripts which is referencing the script you removed, as the error says.

avatar image Eastwing · Dec 11, 2014 at 01:29 PM 0
Share

At first I thought so, but unfortunately it is an issue. In my script (manager) there is only two references to component: adding and destroying. According to debugger error causes between end of OnInspectorGUI function and its beginning. So I guess I must redraw whole Inspector manually. Or, maybe, it's Unity 4.6 bug.

avatar image GameVortex · Dec 11, 2014 at 01:49 PM 0
Share

Showing some scripts from where it says the error happens could help a lot. =)

To redraw the inspector you can use the Repaint function of the Editor class. You could also try to use the EditorGUIUtility.ExitGUI() after you destroy the component to force Unity to start drawing from the top again, although it should not be necessary.

avatar image Eastwing · Dec 11, 2014 at 10:32 PM 0
Share

Sure I know that showing code is a best practice, but there is nothing to see, honestly :) It's just AddComponent by pressing button and DestroyImmidiate by presing other one.

But EditorGUIUtility.ExitGUI() works fine, error no longer appears. Thanks a lot!

1 Reply

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

Answer by Eastwing · Dec 11, 2014 at 10:28 PM

EditorGUIUtility.ExitGUI() is exactly what I need. Thank you, GameVortex!

Comment
Add comment · Show 2 · 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 SevenDays · Oct 25, 2015 at 05:29 PM 0
Share

Thank you! Spend many hours figuring this!

avatar image steven3Dim · Jun 22, 2017 at 09:49 AM 0
Share

This doesn't work for me. It just leaves me with 2 errors. Now I also have: "ExitGUIException: Exception of type 'UnityEngine.ExitGUIException' was thrown.".

Do you call EditorGUIUtility.ExitGUI() immediately after DestroyImmediate()? Or do you call it somewhere else?

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Refreshing custom Inspector window while playing 1 Answer

Custom "Can't add due to conflicting component" 1 Answer

Custom editors for component/class attributes 1 Answer

2D Animation does not start 1 Answer

Sloppy HingeJoints 0 Answers


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