Search Unity

[SOLVED] OnAnimationIK() not called in 2019.3

Discussion in 'Animation' started by the_mr_matt, Dec 17, 2019.

  1. the_mr_matt

    the_mr_matt

    Joined:
    Jul 21, 2015
    Posts:
    124
    Hello!

    I'm having great difficulty setting up an IK animation.
    Steps I have tried:
    1. Setting model to humanoid
    2. Apply root motion
    3. Set base layer to IK
    4. Add another layer for IK
    5. Add a simple idle animation
    Here is my code. "test" is never logged to the console.

    Code (CSharp):
    1. [SerializeField] protected Transform m_LeftHandTarget;
    2. [SerializeField] protected Transform m_RightHandTarget;
    3.        
    4. private Animator m_Animator;
    5.  
    6. private void Start() => m_Animator = GetComponent<Animator>();
    7.  
    8. private void OnAnimatorIK(int layerIndex)
    9. {
    10.     Debug.Log("test");
    11.  
    12.     Assert.IsNotNull(m_Animator);
    13.     Assert.IsNotNull(m_LeftHandTarget);
    14.     Assert.IsNotNull(m_RightHandTarget);
    15.            
    16.     // Left Hand
    17.     m_Animator.SetIKPositionWeight(AvatarIKGoal.LeftHand, 1f);
    18.     m_Animator.SetIKRotationWeight(AvatarIKGoal.LeftHand, 1f);
    19.     m_Animator.SetIKPosition(AvatarIKGoal.LeftHand, m_LeftHandTarget.position);
    20.     m_Animator.SetIKRotation(AvatarIKGoal.LeftHand, m_LeftHandTarget.rotation);
    21.  
    22.     // Right Hand
    23.     m_Animator.SetIKPositionWeight(AvatarIKGoal.RightHand, 1f);
    24.     m_Animator.SetIKRotationWeight(AvatarIKGoal.RightHand, 1f);
    25.     m_Animator.SetIKPosition(AvatarIKGoal.RightHand, m_RightHandTarget.position);
    26.     m_Animator.SetIKRotation(AvatarIKGoal.RightHand, m_RightHandTarget.rotation);
    27. }
     
  2. the_mr_matt

    the_mr_matt

    Joined:
    Jul 21, 2015
    Posts:
    124
    Solved.

    Had to set the avatar in the animation component...