OnTriggerExit2D failure or something else?

I need two opposing waves of enemies to rush at each other and stop and fight when they get close. I use OnTriggerEnter2D for this. One eventually dies and the other needs to continue moving. There I have a problem - using OnTriggerExit2D does nothing. (checked with Debug.Log(“xxx”), it doesnt trigger at all)

I destroy the dead enemy with Destroy(gameObject);

Please help me.

I don’t think OnTriggerExit calls when one object is destroyed. Somebody more experienced may have a better solution, but if it were me, I’d have each enemy store a reference to the enemy object it is fighting (you can get it with OnTriggerEnter), and have a condition in Update checking to see if that object is null.

1 Like