- Home /
OnAnimatorIK Help
Okay so I can't believe I'm hung up on this but I have read every thread out there and I can't seem to figure out why OnAnimatorIK is not being called.
I have a character which already has basic movement animations. I created an IK script and put it on the same gameobject the animator is. I then checked the IK pass box in the layer( there is only one layer right now). When I debug, my OnAnimatorIK never get's called.
Please any insight as to what I'm missing because I seem to be failing to find it.
Here is the code for my IKHandling
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class IKHandling : MonoBehaviour {
private Animator Animator;
public float IKWeight;
public Transform LeftIKTarget;
public Transform RightIKTarget;
public Transform HintLeft;
public Transform HintRight;
private void Start()
{
Animator = GetComponent<Animator>();
}
private void OnAnimatorIK(int layerIndex)
{
Animator.SetIKPositionWeight(AvatarIKGoal.LeftHand, IKWeight);
Animator.SetIKPositionWeight(AvatarIKGoal.RightHand, IKWeight);
Animator.SetIKPosition(AvatarIKGoal.LeftHand, LeftIKTarget.position);
Animator.SetIKPosition(AvatarIKGoal.RightHand, RightIKTarget.position);
Animator.SetIKHintPositionWeight(AvatarIKHint.LeftElbow, IKWeight);
Animator.SetIKHintPositionWeight(AvatarIKHint.RightElbow, IKWeight);
Animator.SetIKHintPosition(AvatarIKHint.LeftElbow, HintLeft.position);
Animator.SetIKHintPosition(AvatarIKHint.RightElbow, HintRight.position);
}
}
Still struggling with this. Starting to think this is a Unity bug.
Answer by ADAMN721 · May 27, 2017 at 07:40 PM
Just figured out my problem. It was that my rig & animation clips were not set to humanoid.
That's right. Thank you ! Switch imported rig to humanoid and activate the checkbox "I$$anonymous$$ Pass" in the layer of the animation controller. And OnAnimatorI$$anonymous$$ () works.
The docs don't even mention "I$$anonymous$$ Pass" needs to be set, which is very sad. I wasted so much time on this until I read your post, thanks. ;)
Answer by the_Whizzkid · Jul 08, 2020 at 10:32 AM
@ADAMN721: Thanks for the hint where to look, I solved it now different (with Unity 2019.4: ) in the Animator, Layers, Layer -> Options/Settings : marked the "IK Pass" and it works.
Answer by Ghosthowl · Apr 10 at 01:28 AM
I also had the same problem and nothing worked for me and I finally realized the script MUST be on the same object that the Animator component is attached to or it will not be called.