Needing help for a script to change the attack animation for a combo

Hi
So, here is the context: for the project I’m working on, I have at the moment a character with a simple attack procedure (press button → single attack). What I want to do is to implement a combo system with different animations.

I already have the technical part of the combo done, i.e. it does attack number 1, number 2, etc… with their respective amount of damage. What does not work however is the part of changing the animation during each hit of the combo.

For my code structure, I have made a few ScriptableObjects to store the data of the weapon, and of each single attack (for now, just three)
I have the WeaponData object here that stores each attacks

public class WeaponData : ScriptableObject
{

    public List<AttackData> attacks;
    public int comboTime;

}

I went through two ideas to try to do this, but none of them fully worked

Idea n°1: to put all four animation clips as parameters of the AttackData so the script gets them and implements them

public class AttackData : ScriptableObject
{

    public int damage;
    public AnimationClip clipTop;
    public AnimationClip clipBottom;
    public AnimationClip clipLeft;
    public AnimationClip clipRight;

}

So, on the code of my attack function, I wrote that

animator.runtimeAnimatorController.animationClips[8] = weaponManager.weaponData.attacks[combo-1].clipBottom;
animator.runtimeAnimatorController.animationClips[9] = weaponManager.weaponData.attacks[combo-1].clipLeft;
animator.runtimeAnimatorController.animationClips[10] = weaponManager.weaponData.attacks[combo-1].clipTop;
animator.runtimeAnimatorController.animationClips[11] = weaponManager.weaponData.attacks[combo-1].clipRight;

(note, it’s placed just after the script gets at what part of the combo the character is in, so the weaponManager.weaponData.attacks[combo-1] part just gets the AttackData of that specific attack)

However, this does not seem to work. I’ve tried to put console logs all over this part of the code trying the different variables and things and it doesn’t assign the animation clips. By the way, I tried to do the exact same thing creating an AnimatorOverrideController object on the script, copy the original animator controller data on it, and assign the clips on it the same way, still doesn’t work.

Idea n°2: to have an override controller directly as a parameter of AttackData instead of the four clips

public class AttackData : ScriptableObject
{

    public int damage;
    public RuntimeAnimatorController overrideController;

}

This way, I prepared one new animator controller for each combo, overriding the default one and just changing the specific needed animations. And for the attack script code, it’s simplified as:

animator.runtimeAnimatorController = weaponManager.weaponData.attacks[combo-1].overrideController;

However, this still doesn’t fully work. While it does show up the animations, it doesn’t show the correct ones. When I try to hit on the left or right, characters hits downwards, then second hit upwards, and things like that, directions are a huge mess. And I double-checked, the animations are correctly assigned 7998810--1028349--upload_2022-3-27_20-19-45.png

So, yeah here is the problem
TLDR: I didn’t find a way to change animation in-script for combo attacks. I’ve tried two methods and both don’t work.
Any ideas ?

I’ve never seen someone try to change animation clips to get this combo effect.

Usually you make a single Animator with the requisite properties and a state machine with transitions to do all the combos / sequences you need, as each transition often needs to be tweaked for overlap and timing.