- Home /
IK not moving hand or calling OnAnimatorIK(int layer)
I've been trying to use the unitydocs example to make my character grab an object. However, OnAnimatorIK() is not being called and when I copy pasted the code into Update() the hand did not move even though the if statements to set the hands position were executed.
I'm using Unity5
The rig is configured as humanoid in Unity.
I've tried it with root motion on and off.
I have a animation layers for my upper body and lower body.
The character can play animations(idle, walking) through the mechanim state machine.
IK pass is checked to true in the animator for both layers.
Both my upperbody layer and lower body layers have animations.
The hand's target is properly set.
My avatar mask for upperbody excludes the legs and their IK's while my avatar mask for the lowerbody only includes the legs and their IKs.
I've tried it with and without avatarLayermasks
The script is attached to the top level gameobject of the character which also contains the animator.
The left hand in the humanoid configuration is set to the left hand gameobject of the character that I wish to move.
void OnAnimatorIK(int layer) { // Was executed in Update() but not in OnAnimatorIK(int layer) if (ikActive) { // Was executed in Update() if (this.lookTarget != null) { animator.SetLookAtWeight (1); animator.SetLookAtPosition (this.lookTarget.position); } // Set the right hand target position and rotation, if one has been assigned if ( lookTarget != null) { //I had a Debug.log here that was executed in Update() // however the position of the hand did not move. animator.SetIKPositionWeight (AvatarIKGoal.LeftHand, 1); animator.SetIKRotationWeight (AvatarIKGoal.LeftHand, 1); animator.SetIKPosition (AvatarIKGoal.LeftHand, lookTarget.position); animator.SetIKRotation (AvatarIKGoal.LeftHand, lookTarget.rotation); } } else { animator.SetIKPositionWeight (AvatarIKGoal.LeftHand, 0); animator.SetIKRotationWeight (AvatarIKGoal.LeftHand, 0); animator.SetLookAtWeight (0); } }
Did you find a solution for this? I am having the same problem.
Did you ever figure this out? I am having a similar issue, where everything is see$$anonymous$$gly set up properly but the OnAnimatorI$$anonymous$$() method is not being called.