- Home /
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?
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.
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.
Your answer
Follow this Question
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