Deleted object fires OnTriggerEnter2D

I’m getting a OnTriggerEnter2D event with and object that was just deleted.

I’m using the following code to recycle my enemies:

int   max = Chunks-1;         
float px  = FirstX;
for(int i=0;i<max;i++){
   Chunk *= Chunk[i+1];*

tChunk = tChunk[i+1];
tChunk*.localPosition = new Vector3(px,0,0);*
px += ChunkWidth;
Chunk[max] = (GameObject) Instantiate(Prefab[Current]);
tChunk[max] = Chunk[max].transform;
tChunk[max].parent = tRoot;
tChunk[max].localPosition = new Vector3(px,0,0);
Chunk is an array of GameObjects while tChunk contains its respective transforms. Enemies (colliding objects) are contained inside the Prefabs I’m instantiating. So when I delete the first chunk all child objects are supposed to be deleted too… and they seem to be, since they disappear from the Hierarchy window… but oddly enought, sometimes I get an OnTriggerEnter2D event from the object that was just deleted.
To make sure I inserted some Debug.Log’s in my code and what I get on the console is this:
BackgroundScroll called:
Destroy Enemy1 at: X=-6.57
OnTriggerEnter2D called:
Crash with Enemy1 at: X=-1.57
Since I’m making sure to have only one enemy of each type is on screen at any given time, the previous log referes to the same object.
Now the value of ChunkWidth is 5… that’s why I suspect of the previous code, but I cannot understand why Chunk[0] the deleted one is changing position, and thus fall in the collision range, and even generate a collision event when it no longer exists.
Any Ideas?


just added:

tChunk[0].parent = null;

Before deleting the object…

It seems like Unity treats anything you do in your script as an atomic operation… so the general efect of deleting an object first or last is exactly the same, it also means anything you do to the parent object afects children, deleted or not. So, if you delete a child object and then move the parent object, the transform of the deleted child object is also affected…

It also seems like Unity doesn’t realize the object is deleted immediatly, so if while changing its position it happens to collide with something, a collision is triggered, even when you had taken care to delete the object first!!!