- Home /
Blender Animations not working properly.
Okay, so I've searched around for a couple of hours now trying to find an answer that fixes this problem I'm having but haven't been able to find one. I've made a character that only has 8 bones. Its a very simple RTS character I've imported it from blender, with all its animations, I've cut the animations in unity to be the right timing and all that stuff. But when I try to get them to work in game they don't. I imported them as a Legacy Type for the rig, and they work just fine playing them in the preview window. I've applied all the changes. Yet when I run the game they don't work, would it be problem with my scripting? or the fact that I imported the model with the animations as an FBX?
Note: after messing around with it for a while I've managed to get the Idle animation to play but that's the only one that will play out of the 10 animations I have...
Here's my code that's supposed to animate them, I'm sure there's something wrong with it, but I'm still very new to coding.
public var idleAnimation : AnimationClip;
public var walkAnimation : AnimationClip;
public var runAnimation : AnimationClip;
enum CharacterState
{
Idle = 0,
Walking = 1,
Running = 2,
}
// ANIMATION sector
if (CharacterState == 2)
{
animation.Play("Run");
}
if (CharacterState == 1)
{
animation.Play("Walk");
}
if (CharacterState == 0)
{
animation.Play("Idle");
}
Answer by Xtro · Aug 09, 2013 at 08:57 PM
Animation component can't play an animation clip if the clip is not registered into the components animation list earlier.
Just make sure if you have all these animations in the component's animation list in the inspector.
Because of that reason, In the script code, we generally refer the animations by their name (string type) instead of the link to the clip itself.
Clips are already (must be) listed in the animation component. There is no need to link them again. Just access them by their names...
instead of this:
public var idleAnimation : AnimationClip;
write
public var idleAnimation : string;
and Type the clip name into this field in the inspector. Clip must be listed in the Animator component.
for playing, write this code...
animation.Play(idleAnimation);
Now, I'm getting an error saying "The animation state could not be played because it couldn't be found! Please attach an animation clip with the name " or call this function only for existing animations.
When I click this error it sends me to this line of code.
animation.Play(idleAnimation);
EDIT: So when I type
public var idleAnimation : string;
I'm given this error. "The name 'string' does not denote a valid type ('notfound'). Did you mean 'System.Runtime.CompilerServices.StrongBox'?"
But when I type it like this...
public var idleAnimation : String;
I don't get an error but the animations still won't play.
yes it should be uppercase String. I'm a C# programmer. That's why wrote it as lowercase.
Like I said before, animation clips must be registered in the animation component. I mean manually. From the inspector.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
How to export MMD model to Unity? 0 Answers
Need help with some OnTrigger Scripting 2 Answers
Animation stoping!! 1 Answer
Help with an animation script. 1 Answer