Error: MissingComponentException: There is no 'Animator' attached - Animator is attached but disappears on play. Can anyone fix?

My script:

using UnityEngine;
using System.Collections;

public class TriggerElevatorDoors : MonoBehaviour 
	public	Animator anim;
	bool areDoorsOpen = false;

	// Use this for initialization
	void Start () 
		anim = GetComponent<Animator>();
	// Update is called once per frame
	void Update () 

	void OnTriggerEnter(Collider openDoorCollider)
		Debug.Log ("Elevator door triggered");

			// elevatorDoorsController.SetTrigger ("ElevatorDoorTrigger");
			anim.SetBool ("isOpen", true);
			areDoorsOpen = true;
			anim.SetBool ("isOpen", false);
			areDoorsOpen = false;

I have a trigger set to open an elevator door. When triggered I get the error:

MissingComponentException: There is no ‘Animator’ attached to the “ElevatorDoorTrigger” game object, but a script is trying to access it. You probably need to add a Aniamtor to the game object “ElevatorDoorTrigger”. Or your script needs to check if the component is attached before using it.

The problem is that the Animator is definitely assigned but when I click play it disappears. I can’t seem to find anyone else having this issue, might be searching for the wrong thing.

Is this the ONLY script attached to the gameobject?

You can try adding:

[RequireComponent (typeof (Animator))]
public class TriggerElevatorDoors : MonoBehavior

Does ANYTHING else reference the gameobject?

And lastly, are you sure you’re not adding the component in play mode…then when you click play (back to edit mode) it reverts?

Fixed it. Took out line 16:

// anim = GetComponent<Animator>();

The animator component is part of a different GO.

Thanks for answering.

In order:

  • It is the only script attached.
  • Added that code but no luck.
  • Nothing else references the gameobject.
  • I’m not adding anything during play mode.

I’m new to animation and the animator in Unity, I very much appreciate the help!