Search Unity

Animator: Get another state by script (not current one)

Discussion in 'Animation' started by unity_W3rLGozcKkUuGg, Jul 16, 2019.

  1. unity_W3rLGozcKkUuGg

    unity_W3rLGozcKkUuGg

    Joined:
    Apr 25, 2019
    Posts:
    11
    Hi guys,

    I want to get, in run-time, what animation is in a certain state that are not the current one.
    (So I can get the animation that is replacing that one into the animator override and do some stuffs using that result).

    Anyone know a way to get that states by using animator tag, or, using a hash, or, state name, or, directly from the playable, or, any other way that this is possible?

    I'm trying to avoid to deal directly with the animations since I don't want the code to be coupled with an animation name.

    Thanks in advance.
     
  2. Kybernetik

    Kybernetik

    Joined:
    Jan 3, 2013
    Posts:
    2,570
    It's not possible to access the details of any states other than the currently active one and the one being transitioned towards at runtime.

    You could gather what you need in the editor by casting the RuntimeAnimatorController to a UnityEditor.Animations.AnimatorController and then serialize those details yourself.

    Or if you want to avoid the need to mess around with Animator Controllers and overrides entirely, you should check out my Animancer plugin (link in my signature) which lets you directly reference the AnimationClips you want to use. Here's an explanation of some of the advantages of that approach.
     
    unity_W3rLGozcKkUuGg likes this.
  3. unity_W3rLGozcKkUuGg

    unity_W3rLGozcKkUuGg

    Joined:
    Apr 25, 2019
    Posts:
    11
    Thanks Kybernetik,

    Funny thing is that you can check if any state exists and get data about the current one but is unable to data from any other one. Frustrating.
     
    Last edited: Jul 17, 2019