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 nikich0601 · Aug 26, 2014 at 11:34 AM · inspectoreditor-scriptingremove

MissingReference after removing component from gameObject

Hi guys. When I am trying to remove a component from my gameobject (doing it via script), I got an error. My code:

 public class Test: MonoBehaviour
 {
     private MeshFilter m_Filter;
 
     public void createMesh()
     {
         if (m_Filter == null)
         {
             m_Filter = gameObject.AddComponent<MeshFilter>();
         }
     }
 
     public void removeMesh()
     {
         if (m_Filter != null)
         {
             if (Application.isEditor)
                 DestroyImmediate(m_Filter);
             else
                 Destroy(m_Filter);
         }
     }
 }

and editor script for this:

 [CustomEditor(typeof(Test))]
 public class TestEditor: Editor
 {
 
     new public Test target
     {
         get
         {
             return base.target as Test;
         }
     }
 
     public override void OnInspectorGUI()
     {
         base.OnInspectorGUI();
 
         if (GUILayout.Button("Create mesh"))
         {
             target.createMesh();
         }
 
         if (GUILayout.Button("Remove mesh"))
         {
             target.removeMesh();
         }
     }
 }


and after clicking "remove mesh" button, mesh get removed, but then exception pops:alt text

after I double-click on exception in console, editor shows next window: alt text

Thanks for help in advance.

exc.png (37.0 kB)
53fc522c38d38708b280302f.png (20.0 kB)
Comment
Add comment · Show 2
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 komodor · Aug 26, 2014 at 01:39 PM 0
Share

there's something else in the project referencing the destroyed meshfilter, might be another component (renderer ?)

it's not so easy to find answer for you, if i cant open the project :D but i'd try to find the thing calling meshfilter OR i'd use different way - for example you could just clear mesh m_Filter.mesh.Clear() while you have the old mesh stored elsewhere ... it depends on how often you use the methods etc.

avatar image Coldcalifornian · Oct 02, 2014 at 07:22 PM 0
Share

Any luck resolving this issue? I'm having the same problem.

0 Replies

· Add your reply
  • Sort: 

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

23 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Script to create instance from in inspector 2 Answers

How to record hideFlags for Undo/Redo 0 Answers

How To Force an Inspector to Repaint 3 Answers

Get the highlighted variable in the inspector 0 Answers

How i can subscribe to an Event through Inspector 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