Despite adding the ‘using UnityEngine.Animations.Rigging’ header atop the script, it still cant resolve the ‘Rigging’ class inside ‘Animations’. Specifically, it can’t reference the ‘TwoBoneIKConstraint’ class.
It’s a simple class as seen below. The script can use other unity types just fine, so why not the types from the animation rigging package? Here’s the script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Animations.Rigging;
public class TwoBoneIkWeightByAnimationTrack
{
public bool Graduating { get; set; }
public void GraduateIkWeight(MonoBehaviour caller, Animator animator, string animationState,
List<TwoBoneIKConstraint> twoBoneIkConstraints, bool inverse)
{
if ( Graduating ) return;
caller.StartCoroutine(GraduateWeight(
animator,
animationState,
twoBoneIkConstraints,
inverse));
}
private IEnumerator GraduateWeight(
Animator animator,
string animationState,
List<TwoBoneIKConstraint> twoBoneIkConstraints,
bool inverse)
{
Graduating = true;
AnimatorStateInfo animStateInfo = animator.GetCurrentAnimatorStateInfo(0);
if ( !animStateInfo.IsName(animationState) ) yield break;
float percentComplete = 0f;
while ( percentComplete < 1f )
{
foreach ( var ikConstraint in twoBoneIkConstraints )
{
float normalizedTime = animStateInfo.normalizedTime;
percentComplete = normalizedTime - Mathf.Floor(normalizedTime);
ikConstraint.weight = inverse ? (1f - percentComplete) : percentComplete;
}
}
Graduating = false;
}
}