- Home /
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)
Answer by LukasLicek · Jan 08, 2018 at 02:53 PM
@uniMaxi hi! :) You should use Animator Override Controller.
Manual link: https://docs.unity3d.com/Manual/AnimatorOverrideController.html
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;
}
}
Your answer
Follow this Question
Related Questions
Animator Controller 0 Answers
Why are my animations not working correctly? Thanks! 0 Answers
Character and enemy don't damage each other 1 Answer