• 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 Sipel · Jun 21, 2017 at 03:23 PM · animationanimatorunity5

Problem changing animator state at runtime by code

Hi all, I have a record player with the arm animation that changes his angle when playing. I want to permit the player to revert the direction of playing (the arm animation) and listen to the reversed track. To do this I want to activate the animator state that containes the reversed animation and sets the animation to the right time.

I have done it using this line of code:

 discAnimator.Play (animatorState, 3, normalizedTime);

This seems to work, but when the animation end, the animator get stuck on the transition and only after quite a bit of time (it seems to be related to the animation length) goes to the next state.

Here a screenshot of the transition that very slowly is going into the next state:

img This problem is not present when playing the animation following the natural flow of the animator, but only when I try to force the state change with that line.

Is've found a bug or I'm doing all wrong?

Thanks in advance, Simone

transition.png (36.0 kB)
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 Laiken · Jun 21, 2017 at 05:23 PM

-click the transition (the arrow)

-in the inspector, expand the "settings" section

-see the values "exit time" and "transition duration" and try changing them (or maybe another setting there can solve the problem)

-if the above did not work, try playing with the sliders below settings section

Comment
Add comment · Show 4 · 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 Sipel · Jun 21, 2017 at 11:17 PM 0
Share

I don't think that's the problem. As you can see in the picture, the left part of the animator graph represent the animation of the record player playing forward and the right part represent the record player playing backward. If I start from the state "Idle" both works fine, so the transitions have to be good. The problem occurs only when I try to switch from "ArmForward" to "ArmBackwards" (or viceversa) trought that line of code, which I need because I also have to start the animation from a specific point of the animation timeline and not from the beginning.

avatar image Laiken Sipel · Jun 22, 2017 at 08:53 AM 0
Share

I see. If I understood correctly you want to press a button and make the arm starting rotation in the other direction from that specific position.

It's weird that the transition works correctly when you jump from idle but not when you jump from ArmForward.

I don't why your problem is happening. If you don't figure out, you can try using weights on layers to do what you want (basically, you have the 2 animations playing on different layers at the same time (for instance, one layer with the ArmForward and the other with the ArmBackward (also, make the mask be just the arm)) but leave one of the layers with weight 0. When you want the other animation to happen, you increase the weight of the one you want to happen and lower the weight of the one you don't want to happen. Not sure if it will work perfectly for you, but it's something you may want to try) (look into blending animations to learn more)

avatar image Sipel Laiken · Jun 22, 2017 at 09:29 AM 0
Share

This is an interesting solution, but a problem remains: If the "ArmForward" has been played to 1/3 of the animation length, when i switch to the "ArmBackward", it should be played from 2/3 of the new animation length. and so I need to use the same line to set the animation time. I can do a workaround by setting a float parameter that reverse the speed of the second animation when the switch occurs, but is really a long unclean solution to do something that seems very simple to me. Of course I will try if anything more simple will come out. In the meanwhile, thank you for your help

avatar image Laiken Sipel · Jun 22, 2017 at 09:20 AM 0
Share

Another simpler solution that I found:

http://answers.unity3d.com/questions/965066/unity-5-reverse-animation-play.html

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

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

Related Questions

How to rotate spine by the script, while an animation from the animator is playing? 0 Answers

Imported Blender Animations not Working 1 Answer

Unity 5 Broken Animations? 3 Answers

Changing one keyframe is changing all 0 Answers

2D Animation does not start 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