- Home /
Problems with animated entity
The problem is quite simple. I have an FBX model of a gun, with animations. To be more specific, the model (named WEAPON1), has two child parts. The body (called Arm), and the cannon (Called AXIS_CANNON, which is the animated part). To import the animations, I do the following:
First, I import the FBX into the project explorer by dragging it inside.
I select the imported model, and in the inspector, I create 4 animations, like this:
http://i.imgur.com/4A66TyH.jpg
Now, I drag the weapon model inside the scene.
I create a new C# script, called "WeaponController.cs". Adding the following lines:
private int power; // Use this for initialization void Start () { power = 0; animation.Play("FIRING"); }
I attach it to my WEAPON1 entity. Then, I add the animations trough the inspector, like this:
http://i.imgur.com/F7pO1DH.jpg
I start the game, but nothing happens. No animation plays. I tried a lot of things like, for example, getting the object:
GetComponent("WEAPON1").animation.Play("FIRING");
Or passing the WEAPON1 entity trough the inspector:
public GameObject Weapon;
private int power;
// Use this for initialization
void Start () {
power = 0;
Weapon.animation.Play("FIRING");
}
With no luck. So my last chance is that you point me what am I doing wrong...
The only clue is that the console give me a few warnings telling me that I should mark my animations as 'Legacy', but I have no clue on how to do that.
Thanks in advace!
Answer by TonyLi · Apr 24, 2013 at 01:20 PM
Select WEAPON1 and go to the Inspector's Rig tab. In the drop-down, select Legacy, then click Apply.
Then go to the Animations tab and make sure all of your animations look okay.
You should notice that your game object will no longer have an Animator component. It should only have an Animation component. (Right now, it has both.)
At this point, it should work.
If it doesn't, then, as a test, drag the FIRING animation into the Animation field at the top of the Animation component. Disable your WeaponController.cs script (uncheck the checkbox in Inspector). Try running again. Since Play Automatically is checked, it should start playing the FIRING animation immediately. If you didn't select Loop in the Animation import, it will only play once. Once you've confirmed that this is working (without any scripts that you've written), you can go back to your script and get that working, too.
Yeh, seems like setting my animations as Legacy was my problem. Your answer helped me and the problem is solved. $$anonymous$$any thanks!
Your answer
Follow this Question
Related Questions
How do I prevent Unity overshooting graph curves? 0 Answers
Child problem in animation 1 Answer
Blender FBX repeated animations 1 Answer
FBX file animation problem 0 Answers
Help with textures 0 Answers