Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by EscTheCtrl · Aug 09, 2013 at 08:19 PM · animationblender

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");
         }
 
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0

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);
Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image EscTheCtrl · Aug 09, 2013 at 09:33 PM 0
Share

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.

avatar image Xtro · Aug 09, 2013 at 11:02 PM 0
Share

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

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

15 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges