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
there’s no need for tricks with empty or duplicate state …
3 Answers
3you 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);
Thank you so much! I didn't take a week, but I did take like two hours trying to figure this out. Might have been a week if you didn't already put the week in for me...
– negative_zeroBeautiful. Thank you so much. The documentation @Box_Frog shared, Unity - Scripting API: Animator.Play, is also very clutch if you are interested in how or why this works.
Beautiful. Thank you so much. The documentation @Box_Frog shared, Unity - Scripting API: Animator.Play, is also very clutch if you are interested in how or why this works.
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 admin with more points than me please re-open this?
– Ash-BlueA post over 6 years old and still massively helpful. Has just helped me with a proble I was struggling with for a long time.
– SecondLegendHi komondor, I think using animator.Play(0) or animator.Play(null) can restart the current state too...
– YwordI'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.
– Ash-BlueBeautiful. Thank you so much. The documentation @Box_Frog shared, https://docs.unity3d.com/ScriptReference/Animator.Play.html, is also very clutch if you are interested in how or why this works.
– GuirieSanchez