- Home /
Why am i getting this error
I have a cube, with a character controller, and when i move on top of a platform, i want it to wait for so manny seconds then it to be destroyed so the player will fall, but it comes up with this error ;
The object of type 'BoxCollider' 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.
here is the code i am using
if(hit.gameObject.tag == "Dropping") { yield WaitForSeconds(4); collider.enabled = false; Destroy(hit.gameObject); }
How should i got about this or fix it.
Answer by MarkFinn · Sep 30, 2012 at 03:48 PM
This is crude, but might do the trick...
if(hit.gameObject !=null && hit.gameObject.tag == "Dropping") { yield WaitForSeconds(4); collider.enabled = false; Destroy(hit.gameObject); }
Answer by whydoidoit · Sep 30, 2012 at 03:55 PM
If what @MarkFinn suggests doesn't work out - it might be because the hit has gone after the 4 second delay. In which case you could try doing var something = hit.gameObject; then the wait, then Destroy(something)
Your answer
Follow this Question
Related Questions
Quick question about destroying bullets/objects 1 Answer
c# and game objects active state issues 1 Answer
Why won't my script load? 1 Answer
Destroyed Object Stops Scipt 1 Answer
Why Can't I Destroy This Object? 4 Answers