onCollisionEnter2D not working?alsifhvblaksfhbgjk

Making a 2D game involving an enemy attacking the player.

When the enemy collides with the player, an OnCollisionEnter2D method in supposed to be called but its not and I have no idea why. The player and enemy both have box colliders and Rigidbody2D’s that are set to dynamic. I have a Debug.Log inside the OnCollisionEnter2D so I know that its not getting called.

the method is on the bottom of the code block.

public class chaserEnemy : MonoBehaviour
{
    private Rigidbody2D rb;
    private Collider2D coll;

    public float moveSpeed;

    public int damage;

    public Transform target;

    // Start is called before the first frame update
    void Start()
    {
        rb = GetComponent<Rigidbody2D>();
        coll = GetComponent<Collider2D>();
    }

    private void Update()
    {
        if (target.position.x > transform.position.x)//if player is to the right of enemy
        {
            transform.localScale = new Vector2(1, 1);//make the character face right
            rb.velocity = new Vector2(moveSpeed, rb.velocity.y);//move character to the right
        }

        if (target.position.x < transform.position.x)//if player is to the left of enemy
        {
            transform.localScale = new Vector2(-1, 1);//make the character face left
            rb.velocity = new Vector2(-moveSpeed, rb.velocity.y);//move the character to the left
        }
    }

    public void OnCollisionEnter2D(Collider2D collision)
    {
        Debug.Log("object hit");

        if (collision.gameObject.layer == 3)
        {
            collision.GetComponent<playerHealth>().damaged(damage);
            Debug.Log("player hit");
        }
    }
}

This may work i dont know.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Example : MonoBehaviour
{
    void Update()
    {
        
    }
            private void OnCollisionEnter2D(Collider2D other)
        {
             if (other.gameObject.name == "Player")
             {
               Debug.Log("Player Hit");
             }    
        }
}

just replace Debug Log with the player lose health part