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 Daev · Aug 10, 2010 at 02:24 AM · errorobjectnullmissingreferenceexceptiondestroyed

Destroyed Object Error

I have been getting a nagging error on pickup objects when they get destroyed.

I have attached a particle emitter to the object which gets detached before the object is destroyed but I'm not sure that this is influencing the problem since I turn off this section and still get the error.

I detach this of course, because I want to have something happen to show you picked something up, and it has to linger after the object is destroyed otherwise it will be destroyed immediately.

Here is the error:

MissingReferenceException: The object of type 'MeshCollider' 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.

if (hit.gameObject.tag == "TRASH_BEGIN" ) {

     audio.PlayOneShot(goodSound);

     var blah : GameObject = hit.gameObject; 

     var emitter : ParticleEmitter = hit.gameObject.GetComponentInChildren(ParticleEmitter);
         if (emitter)
         emitter.emit=true;

     blah.transform.DetachChildren();


     trashPickup ++;
     if (trashPickup >= getExtraLIFE ) 
     {
         ScoreKeeper.lives++;
         trashPickup = 0;
     }


     Destroy(hit.gameObject);
     TemperatureGauge.temperatureAdjust = .05 ;

     ScoreKeeper.timeLeft += 2;
     yield WaitForSeconds(.25);
     TemperatureGauge.temperatureAdjust = 0 ;

 }

Has anyone seen this or can you point me in the right direction so I can clean this up?

Comment
Add comment
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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Tuti · Aug 10, 2010 at 07:15 AM

I think you don't need the "blah" variable at first place. There's probably some script either on the transforms that you detached or on other object that is trying to use your destroyed gameObject, more specifically a mesh collider. I would try to replace the mesh collider with a box collider or sphere collider since your object is a collectable "pickup" I think? Box or sphere colliders takes much less cpu when using to movable objects.

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

Answer by Daev · Aug 11, 2010 at 05:30 AM

okay I tried these suggestions with no luck but it got me deeper into debugging my script.

It turns out that my collision check was doing a check for what if I hit different objects, what happens then however it went from one if statement to another, not followed by an else if.

I added else if to my collision checks, and this cleaned up my logic.

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

No one has followed this question yet.

Related Questions

Trying to access destroyed object 1 Answer

Missing Reference after null Check 4 Answers

Detect if Transform is destroyed 2 Answers

script trying to access a null gameobject's collider... can't fix 2 Answers

MissingReferenceException Help 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