OnAnimatorIK() only works on the same GameObject?

I’m trying to have a wrapper object control the Animator IK but it doesn’t seem to work. The OnAnimatorIK() is not called unless its on the same object as the Animator component. I suppose it makes sense.

I suppose the only way to handle this is to have a proxy which is placed with the Animator that handles the OnAnimatorIK() pass while i control variables from the parent object’s scripts?

Example code I’m using below. Is there a different way to do this or do I need to make a proxy?

using UnityEngine;
using System.Collections;

public class IKthing : MonoBehaviour
{
    public Transform objToPickUp;
    public GameObject goWithAnimator;
    private Animator animator;

    void Start()
    {
        animator = goWithAnimator.GetComponent<Animator>();
    }
    void OnAnimatorIK()
    {
        Debug.Log("Doing IK pass.");
        float reach = 1f;
        animator.SetIKPositionWeight(AvatarIKGoal.RightHand, reach);
        animator.SetIKPosition(AvatarIKGoal.RightHand, objToPickUp.position);
    }
}

Right, we didn’t want to broadcast the callback to other game object because it could decrease performance.

You can make a proxy on your animator’s game object that forward all your OnAnimatorIK to another script.

1 Like

Yep, I moved forward with that. Thanks for confirming. =)

1 Like

Very sorry to revive this post but how does one “make a proxy on your animator’s game object that forward all your OnAnimatorIK to another script”?

You make an OnAnimatorIK method on your Animator’s GameObject, that calls your method on some other GO (where it makes sense for you)

1 Like