Animator throws null reference exception for no reason

Ok, so I’m trying to send a trigger to an Animator so it would transition to the next animation when I call a function.
The script and the animator are on the same game object.

public Animator anim;

 void Start()
    {
        anim = GetComponent<Animator>();
    }

    public void mainMenuEnter()
    {    
        anim.SetTrigger("Next");
    }

The “anim” variable gets successfully populated with an Animation Controller (I can see it through the inspector) but then gives me a null reference exception when i try to do anything with it.
(On the line)

anim.SetTrigger("Next");

I also tried to print it’s name through the Debug.Log but got the same result.
How do i solve this?
Any help would be appreciated.

Oh i figured it out. I was creating an object of the script in another script even though it’s a MonoBehaviour(which caused the error. Don’t declare objects of MonoBehaviours) instead of just referencing it.