leftHandIKTarget is not working.

I made this to change the left hand position, but i get this warning and is not working.

Setting and getting Body Position/Rotation, IK Goals, Lookat and BoneLocalRotation should only be done in OnAnimatorIK or OnStateIK

    void Update()
    {
        OnAnimatorIK();
    }

    void OnAnimatorIK()
    {
        if (animator == null)
            return;

        if (leftHandIKTarget == null)
            return;

        if (leftHandIKTarget)
        {
            animator.SetIKPositionWeight(AvatarIKGoal.LeftHand, 1);
            animator.SetIKRotationWeight(AvatarIKGoal.LeftHand, 1);
            Transform target = leftHandIKTarget;
            Vector3 targetPos = target.position;
            Quaternion targetRot = target.rotation;
            animator.SetIKPosition(AvatarIKGoal.LeftHand, targetPos);
            animator.SetIKRotation(AvatarIKGoal.LeftHand, targetRot);

            Debug.Log("Test A");
        }
        else
        {
            animator.SetIKPositionWeight(AvatarIKGoal.LeftHand, 0);
            animator.SetIKRotationWeight(AvatarIKGoal.LeftHand, 0);

            Debug.Log("Test B");
        }
    }

OnAnimatorIK() is called automatically by the Animator component on the same GameObject. Calling it in Update() is erroneous because it is out of sync with the Animator’s Update cycle, thus throwing that error.

I removed from the Update method, but is not working, the hand position is not changed.

The Animator component calls this method, but it has to be on the same GameObject as the script.

I’m pretty sure the Animator Controller assigned also has to actually use an IK pass on at least one of the layers.

1 Like

Yeah, thx, is working