Search Unity

How to play the animator's default state without knowing the animation's name?

Discussion in 'Animation' started by FeastSC2, Feb 21, 2020.

  1. FeastSC2

    FeastSC2

    Joined:
    Sep 30, 2016
    Posts:
    978
    How to play the animator's default state without knowing the animation state's name?
     
  2. Kybernetik

    Kybernetik

    Joined:
    Jan 3, 2013
    Posts:
    2,570
    It's not possible to do directly. The best you could get is probably an Any State transition based on a trigger parameter called Reset or something.
     
  3. FeastSC2

    FeastSC2

    Joined:
    Sep 30, 2016
    Posts:
    978
    That would mean I need to do this for every animator which is really not handy.

    I found one way is to call on Awake a method Animator.GetCurrentAnimatorState(0).hashCode [not the exact code but it's the idea] and save this value as the default state.