Question by
abourg28 · Nov 21, 2021 at 02:01 PM ·
destroy objectontriggerenter2d
How to check if game object is destroyed?
My OnTriggerExit2D is being called even though the collider has been destroyed. I'd like a way to check whether the colliding object has been destroyed or not. Is there any way to do this short of adding a bool to my colliding object?
Code:
private void OnTriggerEnter2D(Collider2D collision)
{
Destroy(collision.gameObject);
}
private void OnTriggerExit2D(Collider2D collision)
{
// collision.gameObject != null -- Doesn't work
// collision.gameObject.activeSelf -- Doesn't work
Debug.Log("OnTriggerExit2D is being triggered on a destroy");
}
Comment
Best Answer
Answer by abourg28 · Nov 21, 2021 at 10:40 PM
I think this was answered in https://forum.unity.com/threads/does-ontriggerexit2d-activate-when-an-object-is-destroyed.499161/.
Essentially, doesn't work, you need to find another way to cope with destroying objects. For my context, I think I'll simply add a feature to "disable" the game objects and destroy them only when off screen.