GameObject is not detected when using Physics2D.OverlapPointAll()

Hello. I have a problem where a gameObject is not detected.
This is the code from that gameObject and it tried to destroy other gameObject like him if there are more:

private void DestroyExtraRoomConectors()
    {
        Collider2D[] colliders = Physics2D.OverlapPointAll(transform.position,5);
        foreach (Collider2D collider in colliders)
        {
            Debug.Log(collider.gameObject.tag);
            if (collider.gameObject.CompareTag("RoomConector"))
            {
                if (gameObject.GetInstanceID()<collider.gameObject.GetInstanceID()) Destroy(collider.gameObject);
                else Destroy(gameObject); 
            }
        }
    }

This is the GameObject inspector:


The Debug.Log just shows other GameObjects that are not in the layer 5, and that’s strange.
Is more information needed?

1 Like

You can use this to debug and see which gameObject it is:
Debug.Log(collider.gameObject.name);

5 is the index of layer, but you use tag in your debug logging.

Thanks for that advice, but I could solve it. It was related to another part of my code.

1 Like