Q: OnCollisionEnter2D not activating despite collision clearly happening I am working on a platformer where one of the main mechanics is that when you hit enemies from the bottom (or hit them with the top of you as actually implemented in the code) they lose health. It is clear that when running, the player character and the enemy character are indeed colliding, as they affect each other. However, OnCollisionEnter2D, which I use to get the effects, is inclined to disagree, as none of the effects happens when I use them. Here's the current code for it:
void OnCollisionEnter2D(Collision collision)
{
    if (collision.collider.gameObject.layer == 10)
    {
        print("yeet");  //debug text

        if (hitEnemy == true)
            collision.collider.gameObject.GetComponent<EnemyMove01>().health -= 1;
        else
            health -= 1;
    }
}

I tried:


*

*Adding and removing ".collider" from the "collision." lines.

*Adding and removing ".gameObject" from the same lines.

*Using both layers and tags for checking.

*Used both layer name and layer number for checking.

*Removing everything within outer it statement execpt for "health -= 1" and used debug text to see if the problem had anything to do with the way hitEnemy worked (apparently it does not).

*Using both OnCollisionEnter and OnCollisionEnter2D.

*Checked the collider matrix.

*Changed the enemy type to "static".

*Checked if "Is Trigger" is activated (currently it isn't).
I would appreciate any help. I am also willing to post any other things (other parts of code, BoxCollider2D/RigidBody2D stuff) if you think it would help.
Update: I have editted my code and fixed the above problem, but now the enemy character immediately disappears when I run it, even though my character isn't hitting them. Here's the current code:
void OnCollisionEnter2D(Collision2D collision)
{
    if (collision.collider.gameObject.tag == "Enemies")
    {
        print("yeet");  //debug text

        if (hitEnemy == true)
            collision.collider.gameObject.GetComponent<EnemyMove01>().health -= 1;
        else
            health -= 1;
    }
}

And since it might be due to hitEnemy being always true, here's it's activation code:
hitEnemy = Physics2D.OverlapCircle(attackpos.position, attackRange, whatisEnemies);

attackRange is 0.5, while attackpos is attached to a game object which is on top of the player character (I can get a screenshot if you think it would help). whatisEnemies is a layer mask set to the "Enemies" layer.
Update 2: Turns out the second problem what because I forgot to input the enemy's health. Oops.
