Documentation

Unity Engine


User Manual

Script Reference

Unity Engine


OnAnimatorIK(int)

Callback for setting up animation IK (inverse kinematics).
Read time 1 minuteLast updated 4 days ago

Definition

OnAnimatorIK()

public void OnAnimatorIK(int arg0)

Parameters

arg0

Remarks

OnAnimatorIK
is called by the Animator component immediately before it updates its internal IK system. This callback can be used to set the positions of the IK goals and their respective weights.
OnAnimatorIK
is only called if the following requirements are met: - The Animator component must reference an Avatar configured as Humanoid. Generic or Legacy avatars do not support IK. - The Animator Controller layer you want to process IK on must have the IK Pass option enabled. - The Animator component must be enabled and playing an animation on the GameObject. - The script containing
OnAnimatorIK
must be attached to the GameObject with the Animator component. Common uses include: - Setting the position and rotation of IK goals, such as hands and feet, to interact with objects or reach targets in the environment. - Blending between animation-driven and IK-driven motion by adjusting IK weights. - Creating procedural animations, such as looking at a target or reaching for an object. Additional Resources: AnimatorController, Avatar, Animator.

Examples

using UnityEngine;using System.Collections;public class ExampleClass : MonoBehaviour{ float leftFootPositionWeight; float leftFootRotationWeight; Transform leftFootObj; private Animator animator; void Start() { animator = GetComponent<Animator>(); } void OnAnimatorIK(int layerIndex) { animator.SetIKPositionWeight(AvatarIKGoal.LeftFoot, leftFootPositionWeight); animator.SetIKRotationWeight(AvatarIKGoal.LeftFoot, leftFootRotationWeight); animator.SetIKPosition(AvatarIKGoal.LeftFoot, leftFootObj.position); animator.SetIKRotation(AvatarIKGoal.LeftFoot, leftFootObj.rotation); }}