I’ve got a character whose body is controlled via timeline, and I’m leaving their head to be animated via regular animator, as the animations on the head are all lip-synced to what the character is saying. As such, I have animation clips generated for each line of dialogue.
I’d rather not create a billion timelines, one for each line of dialogue, or a billion animator states, one for each line of dialogue, so on the head I have a basic animator set up with a single, 1 frame animation clip on the head in a single base layer which makes the character pull a neutral expression. I’m then using this (abridged) code to attempt to switch the clip in the state through the creation of an animator override controller depending on whether they are speaking or listening:
private Animator _animatorComponent;
private AnimatorOverrideController _animatorOverride;
public override void Ready()
{
_animatorComponent = GetAnimator();
_animatorOverride = new AnimatorOverrideController(_animatorComponent.runtimeAnimatorController);
_animatorComponent.runtimeAnimatorController = _animatorOverride;
}
public Animator getAnimator()
{
// Just some stuff that gets the animator
}
public void setFacialAnimation()
{
_animatorOverride["FaceAnim"] = NewAnimationClip;
}
public void resetFacialAnimation()
{
_animatorOverride["FaceAnim"] = DefaultClip;
}
I’m fairly certain that this is working to an extent - the controller in the head animator is definitely being switched to a new one created by the script, but in the editor nothing really appears to actually change. If I look in the animator, the clip in the state is still the NeutralFace clip.
But, if I breakpoint the code after setting the override and look in the override controller object, I can see that the clip in that state has changed, so for whatever reason, it’s just not updating in the editor.
Despite this, the face isn’t actually animating at all - it’s as if the clip is not playing. Interestingly, if I set the import settings of the clip to loop, it will start playing (though out of sync). Additionally, if I make seemingly any change to the animator while the character is speaking (setting the speed of the clip to be 1.00001, adding a new layer, etc), the clip will suddenly start playing, until the next line starts.
So seemingly, the correct clip is being put in the override, but it doesn’t seem to actually play unless I loop the clip in the import settings (which I don’t want), or I make a manual change to the animator while the game is playing.
Does anyone know why this is?