Swapping animation clips at runtime

I want to create a combat system, where a character has access to ~10 weapon types, all of which have unique animations for idling and autoattacking, as well as 4 special moves.

Thing is, all weapons need to be controlled identically and, while animations are different, animation transitions are essentially governed by the exact same set of rules (accomodating for various animation lengths). So if i were to create an animator controller for each weapon type, i’d then have 10 essentially identical animator controllers.

Is multiple near-identical animator controllers the only way or there is some way to make an abstraction? (F/ex, by assigning relevant clips at runtime)

@uniMaxi hi! :slight_smile:
You should use Animator Override Controller.

Manual link:

It keeps the template of animator and just replaces animations. Then you can swap animations at runtime. Having them stored in weapons scripts would be handy.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class WeaponTemplate : MonoBehaviour {
    
    public int damage;
    //weapon animations override
    public AnimatorOverrideController animationsOverride;

    //character animator
    public Animator anim;

    public void Equip(){
      anim.runtimeAnimatorController = animationsOverride;
    }

}