Can't get animations to play.

I’m having trouble getting animation to play with both the Animation and Animator components and am wondering if my scripting is incorrect.

I have an FBX which was exported from Blender with several Animation Clips:
8873142--1211625--upload_2023-3-13_11-1-48.png

I then made a refab from the FBX file, because I needed to attach some scripts to it, and I cant add components onto a imported model.

I added a Animation component and under its animations list, I placed the 2 animations:
8873142--1211649--upload_2023-3-13_11-15-7.png

In a script I have the following to play the animation:

Debug.Log("Playing Clip: " + _int.Clip_Name + "|" + (anim.GetClip(_int.Clip_Name) != null).ToString());
            anim.clip = anim.GetClip(_int.Clip_Name);
            anim.Play();

However the animations never play. I’ve checked that the clip is found using a debug message Debug.Log((anim.getclip(“clip name”) != null).tostring()). I’ve also checked that the animations work from the preview, and from just directly putting the animation clip into the clip parameters of the Animation Component and setting it to auto play on start, and it plays properly. I’ve also tried switching to the newer Animator component, adding the new animation clips into it and trying that way. Nothing I do seem to work.

Here’s some settings on my imported model - not sure if it has anything to do with it.

Anyone got ideas what I’m doing wrong. I’m using Unity 2021.13.20. Note that I had to put the rig to Legacy Mode because Unity throws me an error telling me I have to if I dont.

Do you have an animation controller and an animation object attached to the prefab?

Can you try to drag and drop the animation of the fbx to an empty GameObject and tell us what the result is when you start play mode?

When i use the Animation component, the component is placed on the Prefab. When I tried using the Animator component, I made a Animation Controller, converted the model to Humanoid, and placed both into the slots of the Animator is placed on the Prefab.

I have to mention that the animation from blender are NLA Strips. Not sure if that has anything to do with it.

That just creates a Animator on the object. The Animator method also doesn’t work for me.

So you tried it with legacy mode, right? Can you give it a try to drag and drop the animation to an empty GameObject with unchecked lagacy mode?

In Legacy mode, it creates the Animation component and adds the animations to the animations list. Seems like what I was doing before

Edit: Without Legacy mode, I simply get an error telling me to put it in legacy mode. It still doesn’t play.

The Animation does play if I place the clip into the Animation slot and I set it to play Automatically. So I don’t think its the animation itself.

Problem Fixed.

The cause was the prefab I made from the object. Apparently I can’t call animations on a prefab made from the importer model and only on the model itself. I moved all the scripts to a separate object and it worked. :slight_smile: