Get original bone position before IK position is set

I use OnAnimatorIK to apply some IK corrections to my character Walk animation and I want to know if it is possible, inside the OnAnimatorIK method, to get the position that a specific joint should have at the current animation frame, if I had never set any IK correction to it.

I tried to read the transform of the joint at the OnAnimatorMove method, but it is already changed because the IK correction is applied from the previous frame.

I also tried to set IK weight to zero and then try to read some values but nothing gave me the result I wanted.

I would like to clarify first, because you mentioned

, did you use the IK API provided by Unity (such as SetIKPosition()) in your OnAnimatorIK(), or did you do some custom processing?

Yes, I use SetIKPosition and SetIKRotation at OnAnimatorIK in order to move the foot joints.

Sadly I don’t have a solution, but I’d like to know as well. I ran into the same problem with Unity’s own Animation Rigging package (3 years ago actually), so I’m all ears :slight_smile:

try this:

       public float weight = 1;

        public static HumanBodyBones GoalToBone(AvatarIKGoal goal)
        {
            switch (goal)
            {
                case AvatarIKGoal.LeftHand:
                    return HumanBodyBones.LeftHand;
                case AvatarIKGoal.RightHand:
                    return HumanBodyBones.RightHand;
                case AvatarIKGoal.LeftFoot:
                    return HumanBodyBones.LeftFoot;
                case AvatarIKGoal.RightFoot:
                    return HumanBodyBones.RightFoot;
                default:
                    return HumanBodyBones.LastBone;
            }
        }

        public Pose GetOriginalGoalPosition(Animator anim, AvatarIKGoal goal)
        {

            anim.SetIKPositionWeight(goal, 0);
            anim.SetIKRotationWeight(goal, 0);

            Transform bone = anim.GetBoneTransform(GoalToBone(goal));
            Vector3 pos = bone.transform.position;
            Quaternion rot = bone.transform.rotation;

            anim.SetIKPositionWeight(goal, weight);
            anim.SetIKRotationWeight(goal, weight);
            return new Pose(pos, rot);
        }