Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question about OnStateEnter

Discussion in 'Animation' started by Alan-Liu, Oct 28, 2016.

  1. Alan-Liu

    Alan-Liu

    Joined:
    Jan 23, 2014
    Posts:
    390
    I have an animation of shooting an arrow. It seems that the position of hand bone is wrong if I access it in OnStateEnter, but it's correct if I access it in LateUpdate. So, is the animation not updated completely before OnStateEnter is called?
     
  2. Mecanim-Dev

    Mecanim-Dev

    Joined:
    Nov 26, 2012
    Posts:
    1,675
    yes exactly,

    There is a fews step in the animation system:
    1. Evaluate StateMachine
    2. Evaluate AnimationClip
    3. Fire Animation Events
    4. Fire StateMachineBehaviour -> OnStateEnter is called here
    5. Apply Root motion.
    6. Retarget Animation for Humanoid
    7. Evaluate IK
    8. Write Animated value to unity

    If you look at the documentation about Unity execution order of events function all those steps are processed in the internal animaiton update
    https://docs.unity3d.com/Manual/ExecutionOrder.html
     
  3. Alan-Liu

    Alan-Liu

    Joined:
    Jan 23, 2014
    Posts:
    390
    Thank you for replying.
    I'm also curious about why the position is wrong if I access in OnStateEnter. I say it's wrong, because it's not at the position of last frame.(It's near to feet when accessed in OnStateEnter, and near to head when accessed in LateUpdate). The position of that hand bone is near to head in the entire animation. As you said, before OnStateEnter, engine don't change the position of bone transform, so I think I should get the position of last frame. (If I understand correctly?)
     
  4. Alan-Liu

    Alan-Liu

    Joined:
    Jan 23, 2014
    Posts:
    390
    I found the issue. The "IsKinematic" of rigidbody on the bone isn't set to true, so it drops due to physics simulation.