No Animation Attached to Object?

Hello, I am currently working on a project in Unity and i use maya 2012 for all my modeling and animation. the problem I am having is that I exported a model with animations in it as an FBX file. the file imported perfectly into unity. I made the animation clips in the inspector and they work perfectly. they play in the preview window and everything. in the rig tab of the object I have it set to generic. However, when I attach a script to the object, it keeps telling me that there is no animation attached to the object. but a script is trying to access it. I can’t figure out why unity can’t see the animations. they play perfectly fine in the preview window and everything.


as you can see, everything is imported correctly(I think). It plays in the inspector but i can’t access it through a script. The script itself is just the simple animation.Play(“Forward”); in the function update. I worked with animation previously but it was the 3.5.7 version. I don’t know if anything changed in importing the animation. Any help would be appreciated.

The best thing to do in your script is to get the animation component into a variable and test it first to see if it exists:

// class member
Animation temp;

void Start() {
    temp = GetComponent<Animation>();
}

// I imagine you're playing the animation in your update function

void Update() {
    if (temp) { // i.e. if the animation exists
        temp.animation.Play("forward", PlayMode.StopAll);
    }
}

I used stop all in the play function just in case other animations were playing by default. If this doesn’t work maybe you need to assign the imported object into an empty gameobject and access it that way.