Animator go to default state by script

Is there any way to make an animator go to its default state animation?
It’s hard to make all animator’s default state name the same, so I can’t simply call Play(“Default Animation”)

Many thanks

Hello,

As far as I know, there’s no easy way of saving the default state as a variable.

The easiest way of going back to the default state is to make a transition to it from “Any State” with a condition, and then control the parameter of the condition through code.

Example: Animator.SetBool("Default", true);

1 Like

Yes, if there is no way to easily go default state, I will do it in your way, but I need to ask my friend to make sure all the animators have the same trigger state called “Default”. As my project already run a while, there are many animators that need to modify. So that’s my final choice.

Thank you~

1 Like

I found an easier way to go back to the default animation state in some cases.
If animation-names equal to state name, then in Start() function save current animation-name as default animation.
So it can easily go back to the default animation state whenever it needs.

For example:


7625053--948571--upload_2021-11-3_15-23-7.png

7 Likes