cherub
October 21, 2011, 4:40pm
1
I am a bit confused here. ive done some research here, but nothing has done the trick so far.
I get the error: The object of type ‘SphereCollider’ has been destroyed but you are still trying to access it.
Reason i am confused: how can the object collide with one that has been removed from the scene?
is there a delay between destroying a G.O. and removing the Collider? or a delay between calling OnTriggerEnter and running the function?
function OnTriggerEnter (Collided : Collider)
{
if (Collided.tag == ("MyTag"))
{
Do Something;
}
}
pezz
October 21, 2011, 5:12pm
2
That is because you have scripts still trying to access the destroyed object.
cherub
October 21, 2011, 5:18pm
3
im not sure how. the “do something” part is doing something to the GO with the script but not to the one with the tag.
all its doing is grabbing the tag from an object that is destroyed after the collider hit…
is OnTriggerEnter called more than one time on a hit?
Destroy destroys the object now but any simulation already has taken place for this frame so its possible that the script is hit none the less.
what you want to do is use DestroyImmediate on the object after disabling the gameobject alltogether
cherub
October 21, 2011, 5:44pm
5
im still not understanding.
the script isn’t telling the destroyed object to do anything. its only detecting if the GO with the script hit it.
i hate when my brain is stuck!
There is nothing destroyed (yet) otherwise it wouldn’t enter it.
thats the point I’m after
cherub
October 21, 2011, 5:48pm
7
hmm, so it is possible that it enters the trigger, and then while its there, if the trigger is destroyed by something else, it returns null?
cherub
October 21, 2011, 7:23pm
8
looks like I fixed it by having the destroyable GO send a message on collide instead of the first GO reacting to the destroyable GO.
in effect, the message can not be sent if the object is not there.