Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Set humanoid avatar pose to it's last frame of various animations instantly

Discussion in 'Animation' started by Cazforshort, Sep 2, 2022.

  1. Cazforshort


    Feb 22, 2016

    I have an issue involving a dynamically scalable avatar and several dozen animations.

    The issue is that I need to create a list of the positions of each hand at the last frame of each animation.
    This needs to be done at runtime since the avatar's height changes with a scale slider, so just going to the frame on the animation scrubber and checking the position won't do.

    I thought I would be able to use the following script, but the results are all off by a lot.

    Code (CSharp):
    1. IEnumerator addTargetPositionToList(){
    3.         Ghost.enabled = true;
    4.         for (int i = 0; i < states.Count; i++) // 12 states
    5.         {
    6.             animator.SetBool("PlayingAnimation", true);
    8.             // set animation to last frame
    9.             animator.CrossFade(states[i], -0f,0 , 1);
    12.             yield return new WaitForSeconds(0.1f);
    14.             // append the target positions to the array. 24 positions total
    15.             leftHandTargets.Add(leftHand.position);
    16.             rightHandTargets.Add(rightHand.position);
    17.         }
    20.     }
    Is there a convenient way to get the last state of an animation? CrossFade just isn't working well.