Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 esitoinatteso · Sep 15, 2015 at 06:37 PM · animationanimatorplaybackwards

Using Animator, How To Play an Animation Backwards

Hi there!

My question is simple:

  • I've tried setting the Animator's speed to -1 and failed;

  • I've tried setting Animation's speed to -1 and found out Animation has no speed parameter;

  • I've tried to understand where can I grab a reference to my AnimationStates, to no avail;

So... How do I play an animation backwards if everything is set up to work with Animators?

It's so simple using the editor: you open up a State Machine, click a State and set the Speed to -1.

How can I do that via script?

Could you please guide me through the steps needed, since Internet has provided me no help with this? I've read a lot of comments and questions asked in the past 9 years but all the references and solutions given seems outdated... or maybe I'm really really dumb who knows!

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
Best Answer

Answer by esitoinatteso · Sep 22, 2015 at 01:37 PM

Bumping the question and adding the workaround I've found out as a possible answer.

I still don't know how to play an Animation Backwards using an Animator but I've managed to achieve what I was looking for using this method:

  1. In the State Machine of the Animator, for each State that you'd like to play Backwards duplicate it and set it's animation speed to -1 via editor.

  2. Allow the two states to transition to one another; you need to make a transition from the original to the duplicate and viceversa... Depending on the complexity of the State Machine you might also need conditional parameters to handle those transitions.

  3. Use a State Machine Behaviour script to handle at runtime the behaviour of the State Machine.

In my case, my State Machines were simple so no conditional parameters were involved... like so:

alt text

And I've used this script to handle the State Machine ( in simple terms, each time a new state is entered I set the Animator's speed to 0 and wait for another script to fix it back to 1, when a proper event happens at runtime):

 // OnStateExit is called when a transition ends and the state machine finishes evaluating this state
     override public void OnStateExit(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) {
 
         //Freeze
         animator.speed = 0;
 
         //Manually set the next state so that everything works and we never miss a beat
         animator.Play(animator.GetNextAnimatorStateInfo(0).shortNameHash,layerIndex,0f);
     }

It works for me :D


screen-shot-2015-09-22-at-144126.png (146.3 kB)
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

30 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

Related Questions

Animation doesn't play 1 Answer

How do I play my animations w. Mechanim? 1 Answer

2D Animation does not start 1 Answer

Animation not be found 1 Answer

Animate an Object by letting it play out in when I press play? 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