Un-Ignore Collision with OnCollisionExit2D

Hi,

i want to ignore the collision between my player and an enemy when the enemy enters the collision of the player.
This works perfectly.

Then i want to unignore the collision when the enemy leaves the collision of the player.
But when i do this, the collision gets ignored and unignored immediatly.

This is my code:

    void OnCollisionEnter2D(Collision2D other)
    {
        if (other.gameObject.tag == "Gegner")
        {
            Debug.Log("Collision Started");
            Physics2D.IgnoreCollision(other.gameObject.GetComponent<Collider2D>(), this.gameObject.GetComponent<Collider2D>(), true);
        }
    }

    void OnCollisionExit2D(Collision2D other)
    {
        if (other.gameObject.tag == "Gegner")
        {
            Debug.Log("Collision Exit");
            Physics2D.IgnoreCollision(other.gameObject.GetComponent<Collider2D>(), this.gameObject.GetComponent<Collider2D>(), false);
        }
    }

This is what my console looks like (the player and the enemy were touching for about 2 seconds):

3759718--313447--collision.PNG

Thanks for your help!

What about a

void OnTriggerEnter2D(Collider2D other)
    {
        if (other.gameObject.CompareTag("Gegner"))
        {
           
Debug.Log("Collision Started");

        }
    }

u only have to set as trigger the collider of the prefab avoiding to manage with these collisions