How can I add sprite frames to an animator dynamically?

Hello there fellow devs. I am trying to find a solution that has plagued me for a while. I had tried to make a custom animation system that was simple with a small footprint. I ran into issues with looping so I decided to switch to Unity’s built in system. I feel like I am almost there. I have all the data passing from elsewhere just fine. This all worked well in the custom thing I made. I am not as familiar with the animation system in particular the AnimatorOverrideController. I will first post the code I have for the animation.

private IEnumerator AnimateFrame(string _sheet, string _start, string _end, string _anim_speed, string _loop) {

        #region FILL anim_sprites
        if (previousSheet != _sheet) {
            previousSheet = _sheet;
            scene_sprites = Resources.LoadAll<Sprite>("Textures/" + GetSceneSheet(_sheet));
        }
        List<Sprite> anim_sprites = new List<Sprite>();
        int start_frame = GetStringValue(_start);
        int end_frame = GetStringValue(_end);
        for (int i = start_frame; i <= end_frame; i++) {
            anim_sprites.Add(scene_sprites*);*

}
#endregion

// Animation Setup
var scene_panel = dialogueScenePanelController.ScenePanel;

_clip = new AnimationClip();
_animator = scene_panel.GetComponent();

EditorCurveBinding spriteBinding = new EditorCurveBinding();
spriteBinding.type = typeof(SpriteRenderer);

int framecount = anim_sprites.Count;

ObjectReferenceKeyframe[] spriteKeyFrames = new ObjectReferenceKeyframe[framecount];

for (int i = 0; i < (framecount); i++)
{
spriteKeyFrames = new ObjectReferenceKeyframe();
spriteKeyFrames*.time = i;*
spriteKeyFrames.value = anim_sprites*;
_}*_

//_clip.legacy = true;
//_animation.clip = _clip;
AnimationUtility.SetObjectReferenceCurve(_clip, spriteBinding, spriteKeyFrames);
Debug.Log("ANIMATING FRAME: " + " Sheet: " + _sheet + " Start: " + _start + " End: " + _end + " Speed: " + _anim_speed + " Loop: " + _loop);

AnimatorOverrideController animatorOverrideController = new AnimatorOverrideController();
animatorOverrideController.runtimeAnimatorController = _animator.runtimeAnimatorController;
animatorOverrideController[“ScenePanelAnim”] = _clip;
_animator.runtimeAnimatorController = animatorOverrideController;

yield return new WaitForSeconds(1);
}
I hope that is clear enough. Here is a screen shot of my setup for where the animation will play. I have it attached to a sub-panel in prefab called DialogueScenePanel. The sub panel with the animator is called ScenePanel. The ScenePanelAnimation Controller is set in the Animator’s controller slot. The scene panel animation is the animation.
[122937-inspectorscreen.png|122937]

What I want to do is I have a signal sent to anmiate_frame function as needed from a dialogue system What I want to do is every time a new signal comes in I want to change the animation (add some new sprite frames and play) Seems simple enought but the error I get currently is…
Cannot nest AnimatorOverrideController ‘’ with ‘’.
UnityEngine.AnimatorOverrideController:set_runtimeAnimatorController(RuntimeAnimatorController)
c__Iterator2:MoveNext() (at Assets/Scripts/Dialogue/DialogueSceneManager.cs:255)
I’m not sure if it’s because it’s (controller) the same name or if I am even doing this right. Any help would be much appreciated. If anything just point me in the right direction.

I keep getting an error when I try to update my post here on the forums so I will post an edit here. I stopped the error from happening by searching for the error itself but the images still are not showing up in the panel or clip. Not sure which if either. Below is my updated code.

private IEnumerator AnimateFrame(string _sheet, string _start, string _end, string _anim_speed, string _loop) {

        #region FILL anim_sprites
        if (previousSheet != _sheet) {
            previousSheet = _sheet;
            scene_sprites = Resources.LoadAll<Sprite>("Textures/" + GetSceneSheet(_sheet));
        }
        List<Sprite> anim_sprites = new List<Sprite>();
        int start_frame = GetStringValue(_start);
        int end_frame = GetStringValue(_end);
        for (int i = start_frame; i <= end_frame; i++) {
            anim_sprites.Add(scene_sprites*);*

}
#endregion

// Animation Setup
GameObject scene_panel = dialogueScenePanelController.ScenePanel;

_clip = new AnimationClip();
_animator = scene_panel.GetComponent();

EditorCurveBinding spriteBinding = new EditorCurveBinding();
spriteBinding.type = typeof(SpriteRenderer);
int framecount = anim_sprites.Count;
ObjectReferenceKeyframe[] spriteKeyFrames = new ObjectReferenceKeyframe[framecount];
for (int i = 0; i < (framecount); i++) {
spriteKeyFrames = new ObjectReferenceKeyframe();
spriteKeyFrames*.time = i;*
spriteKeyFrames.value = anim_sprites*;
_}*_

AnimationUtility.SetObjectReferenceCurve(_clip, spriteBinding, spriteKeyFrames);

// Override Animator
RuntimeAnimatorController runtimeAnimatorController = _animator.runtimeAnimatorController;

AnimatorOverrideController animatorOverrideController = runtimeAnimatorController as AnimatorOverrideController;
if(animatorOverrideController != null) {
runtimeAnimatorController = animatorOverrideController.runtimeAnimatorController;
}
AnimatorOverrideController animatorOverride = new AnimatorOverrideController();
animatorOverride.runtimeAnimatorController = runtimeAnimatorController;
animatorOverride[“”] = _clip;
_animator.runtimeAnimatorController = animatorOverride;

Debug.Log("ANIMATING FRAME: " + " Sheet: " + _sheet + " Start: " + _start + " End: " + _end + " Speed: " + _anim_speed + " Loop: " + _loop);
yield return new WaitForSeconds(1);
}