x


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?

more ▼

asked Aug 10 '10 at 02:24 AM

Daev gravatar image

Daev
97 12 14 19

(comments are locked)
10|3000 characters needed characters left

2 answers: sort oldest

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.

more ▼

answered Aug 10 '10 at 07:15 AM

Tuti gravatar image

Tuti
410 1 3 9

(comments are locked)
10|3000 characters needed characters left

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.

more ▼

answered Aug 11 '10 at 05:30 AM

Daev gravatar image

Daev
97 12 14 19

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

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

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x1951
x1095
x198
x30
x17

asked: Aug 10 '10 at 02:24 AM

Seen: 2342 times

Last Updated: Aug 10 '10 at 02:35 AM