"There is no 'Collider2D' attached" when there clearly is!

I’m trying to activate a collider on my sword object, but it throws out an error:

MissingComponentException: There is no ‘Collider2D’ attached to the “Sword” game object, but a script is trying to access it.

There clearly is a collider attached, I’ve tried changing it BoxCollider2D, with no luck. If anybody could help, I’d appreciate it!

Collider:

I’m trying to trigger the function in an animation:

if(Input.GetMouseButtonDown(1) && !attacking)
        {
            anim.SetTrigger("attack");
        }
void meleeAttack()
    {
        GameObject.Find("Sword").GetComponent<Collider2D>().enabled = true;
        attacking = true;
        Debug.Log("Attack");
    }
    void noMeleeAttack()
    {
       
        GameObject.Find("Sword").GetComponent<Collider2D>().enabled = false;
        attacking = false;
        anim.ResetTrigger("attack");
        Debug.Log("NoAttack");
    }

Any chance you have more than one object named “Sword” in the scene? GameObject.Find will return the first object named “Sword” that it finds, which may not be the one you want. It’s usually better to make a public variable named “sword” in your animation script and then drag the one you want into that slot in the inspector. Especially if you ever have two characters with swords in the scene using the same script.

Also using Find for these stuff is horrible IMHO, both for pref and legibility (hope it autocorrect to the right word haha)

No, the Sword object is the only one in existence. I’ve just restarted Unity to see if it was a bug maybe, and sure enough, the error disappeared, but the debug isn’t being shown either, so the function isn’t running.

I took a look in the animation, and the ‘function selector’ thing had changed from a drop down to this:
http://prntscr.com/j4grjd

edit:
The issue seems to have fixed itself, with little to no input from me. I’m confused, but I’ll take it. Thanks for the attempted help anyway!