So I will explain my current set up, and the problem I am running into. I use sprite-based animation via a sprite sheet on my left and right eye materials. I have set up a custom shader that allows me to control the current frame of the sprite sheet with the intent of animating the eyes for various animation clips. I have an attached script called FaceSpriteAnimator that allows me to directly override these eye frames.
I have various animation clips, such as idle, walk, run, sprint, etc. In some of these clips, I keyframe my eye frames so that I can animate my eyes directly inside the animation clip. The end result is perfect, it works nicely EXCEPT for one thing that I am struggling to solve. Animation blending.
Here's an example that highlights the problem: let's say that my sprint animation uses frame 8 for the left and right eyes - which results in a squint, and let's say my run animation uses frame 0 for both eyes - which is just a neutral expression. In an Animator blend tree, when it is blending between the sprint and run animations, it is ALSO blending the keyframed eye expressions. So what happens is if I go from a sprint to a run, my eye frames quickly go from 8 to 0, causing my eyes to freak out since it's rapidly changing frames.
Ideally, the preferred outcome is that it uses the eye frame animation of the most dominant clip in the animator. So in my above example, it should INSTANTLY go from 8 to 0, instead of 8->7->6... 2->1->0. But this is the part I don't know how to solve.
I can figure out what is the most influenced clip with this code:
using System.Linq;
...
void Update()
{
if (animator != null && Application.isPlaying)
{
var clipInfo = animator.GetCurrentAnimatorClipInfo(0);
if(clipInfo.Length > 0)
{
// Find the clip with the most influence (highest weight)
var strongestClip = clipInfo.OrderByDescending(x => x.weight).First();
print(strongestClip.clip.name);
}
}
}
But I have no clue how I could figure out what the script property value is currently in this animation, as opposed to the blended value that I am getting instead.