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
1
Question by krial057 · Dec 18, 2013 at 05:38 PM · animationbuildmecanimruntime

Access Animation States in Mecanim at runtime

I need to change different properties of states in Mecanim at runtime(Mainly animation-speed and animation-clips). I found a way to make it work:

 UnityEditorInternal.AnimatorController ac = animator.runtimeAnimatorController as UnityEditorInternal.AnimatorController;
 UnityEditorInternal.StateMachine sm = ac.GetLayer(0).stateMachine;
 //set the animationclip to the one that is set for the current attack
 sm.GetState(1).SetAnimationClip(animationClipToolStart);
 sm.GetState(2).SetAnimationClip(animationClipToolEnd);
 //set the speed of the animation so that it ends when startupTime is over
 sm.GetState(1).speed =(float)(animationClipToolStart.length/startupTime);
 sm.GetState(2).speed =(float)(animationClipToolEnd.length/cooldownTime);

It works fine inside the Editor. However, when I try to Build it, I get the error that the UnityEditorInternal Namespace was not found(which makes sense, because Unity probably doesn't export the Editor features for the final game). Therefore, I wanted to ask if there is a way around this error-message, or if someone has an idea for a good alternative.

Comment
Add comment · Show 3
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 petrucio · Mar 03, 2014 at 02:44 AM 0
Share

Same problem here...

avatar image DreamingSpirit · Mar 05, 2014 at 12:04 AM 0
Share

I would like to know the answer to this question also.

$$anonymous$$y current workaround is that I am using .ForceStateNormalizedTime() on the animator when it has found a clip that I have marked as needing a new speed. It then manually sets the progress of the animation.

avatar image krial057 · Mar 05, 2014 at 11:11 PM 0
Share

I now just used the old Animator Component. And wrote the state changing manually per script. In the old Animator Component you can change the speeds.

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by vanmani · Mar 30, 2015 at 04:07 AM

You will be able to solve this problem in 5.1. You cannot currently solve this problem in a good way.

This problem has been experienced by hundreds of users, and relates to the design of Mecanim. The problem seems to be that the state machine is not instanced at runtime - so any changes you make to it at runtime would be permanent. As such, they don't expose any of it at runtime.

They're fixing it by allowing you to drive the speed of an animation state via parameter in 5.1. A bit of a hacky solution if you ask me, but a solution nonetheless.

Wrote all about it on my blog if you want to know more.

Comment
Add comment · 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

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

20 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 avatar image avatar image avatar image avatar image avatar image

Related Questions

Pistol Aim prolbem style = Tomb Raider??? 0 Answers

Mixing Unity Mecanim and Scripted Bones/States 1 Answer

Best way to go about believable 2 Character Grab/Lift animation? 1 Answer

Error getting animation info with Animator 0 Answers

Mecanim add weight to certain animations 0 Answers


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