OnCollisionEnter2D not working

basically I have created a object name square that functions as a basic character controller. when I press and the square the jump button it jumps. i created a trigger which is another game object that simply follows the square around.
I added the ontriggerenter and ontriggerexit functions so that it would mark the grounded variable as true whenever the ground is touched. For some reason this will not work. I can mark the grounded variable as true without the use of the oncollisionenter function and it works fine, if i just have the grounded variable always marked as true the movement works fine. so i have deducted that the issue is in teh oncollsionenter function. Does anybody have a solution for this?
public class FollowPlayer : MonoBehaviour
{
public character_controller square;
// Update is called once per frame
void Update()
{
transform.position = GameObject.Find(“Square”).transform.position;
//this was done to test if the issue i had was with marking the variable true. i can change the grounded vairable’s value easily
if (Input.GetKeyDown(KeyCode.U))
{
square.grounded = true;
Debug.Log(“pressed U key and can now jump”);
}
}

    private void OnCollisionEnter2D(Collision2D col)
    {
        if (col.gameObject.CompareTag("Ground"))
        {
            square.grounded = true;
            Debug.Log("grounded");
        }
    }
    private void OnCollisionExit2D(Collision2D col)
    {
        if (col.gameObject.CompareTag("Ground"))
        {
            square.grounded = false;
            Debug.Log("airborne");
        }
    }


}

At least 1 collider needs a rigidbody component.

In rare cases, check the project settings and collision matrix to make sure both colliders are on layers that collide with each other

This might not be the issue but you said “I added the ontriggerenter and ontriggerexit functions” but in the script itself is OnCollisionEnter and OnCollisionExit. If you use OnTrigger and objects dont have trigger, it doesn’t work, so maybe you made the objects in inspector be trigger but not on script causing the same issue? Oh also make sure the GameObjects have RigidBody.

Your using OnCollision, but you need to use OnTrigger for triggers.