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 /
  • Help Room /
avatar image
12
Question by komodor · Jan 24, 2014 at 12:19 AM · animatorrandommecanimtimerestart

how to restart mecanim state animation or play it from random position [SOLVED]

we've been looking for the answer almost week and we found it and it's pretty simple, so we decided to share for those who are looking too :D there's no need for tricks with empty or duplicate state ...

Comment
Add comment · Show 4
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 Ash-Blue · Nov 04, 2017 at 01:12 AM 0
Share

I'm not sure why this question is closed. There are a variety of other solutions for fixing this problem and it currently sits at the top of the Google search. For example it can be done purely through an animator transition. Or with an Animator Behavior script for re-usability and better code abstraction. I'm about 50 points away from being able to re-open this question. Can an ad$$anonymous$$ with more points than me please re-open this?

avatar image SecondLegend · Sep 07, 2020 at 05:25 PM 0
Share

A post over 6 years old and still massively helpful. Has just helped me with a proble I was struggling with for a long time.

avatar image Yword · Feb 01, 2021 at 08:34 AM 0
Share

Hi komondor, I think using animator.Play(0) or animator.Play(null) can restart the current state too...

avatar image Ash-Blue · Feb 01, 2021 at 04:15 PM 0
Share

I've re-opened this question as there are a variety of potential solutions not covered and it's still sitting at the top of google searches.

1 Reply

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

Answer by komodor · Jan 24, 2014 at 12:19 AM

you can do just:

 Animator.Play(state, layer, normalizedTime);

if you use

 Animator.Play("same state you are", -1, 0f);

it will restart current state, if you put whatever float from 0 to 1 into normalized time, you can set it to any time position you want

you can also use

 Animator.CrossFade(state, crossFadeTime, layer, normalizedTime);
Comment
Add comment · Show 9 · 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 Tony-Sparrow · Sep 25, 2014 at 10:15 AM 2
Share

Nice, thanks you guy, This solved my problem.

avatar image negative_zero · Feb 07, 2015 at 09:25 AM 0
Share

Thank you so much! I didn't take a week, but I did take like two hours trying to figure this out. $$anonymous$$ight have been a week if you didn't already put the week in for me...

avatar image impurekind negative_zero · Aug 23, 2018 at 05:29 PM 0
Share

It took me like two days until I finally stumbled upon this answer. It is a joke that it often takes so long to find what is ultimately a pretty simple solution to a pretty small problem almost every single time.

avatar image Sajalsh25 · Sep 09, 2016 at 03:52 PM 0
Share

You are a genius!

avatar image Alakanu · Jun 07, 2017 at 02:20 PM 0
Share

What does the -1 do though? Doesn't it work with the correct layer's index?

avatar image impurekind · Aug 23, 2018 at 05:18 PM 1
Share

$$anonymous$$y God, finally something that works.

Why is it often sooo complicated to find a solution to something so simple when I do searches for this stuff in Unity!

Also, I still don't quite understand the "layer" part of this function: What does the "layer" do with an animation?

Show more comments

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

28 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

Related Questions

Random Number every 5 seconds 2 Answers

How can I use "animator.SetTrigger()" if "animator.SetBool()" has been true for X amount of seconds? 0 Answers

How to make character animate as he's rotating? 2 Answers

Mecanim animator rotation issue 0 Answers

What's the difference between animator.CrossFade() and a transition in the Mecanim node editor? Are they the same thing? 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