Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

AnimationOverrideController not doing anything. What am I missing?

Discussion in 'Animation' started by BionicWombatGames, Dec 18, 2020.

  1. BionicWombatGames

    BionicWombatGames

    Joined:
    Oct 5, 2020
    Posts:
    33
    I've got an Animator with a bunch of named clips with their motions set to blank:



    In a script attached to the enemy GameObject, I've got the following code:

    Code (CSharp):
    1. public AnimationClip clip; //set in inspector
    2. private void Start() {
    3.     animator = GetComponent<Animator>();
    4.     animatorOverrideController = new AnimatorOverrideController(animator.runtimeAnimatorController);
    5.     animator.runtimeAnimatorController = animatorOverrideController;
    6.     animatorOverrideController["Enemy_Idle"] = clip;
    7.     Debug.Log(clip); //output: "Enemy_Mushroom_Attack_Boom (UnityEngine.AnimationClip)"
    8.     Debug.Log(animatorOverrideController["Enemy_Idle"]); //output: "Null"
    9.   }
    This does nothing. The Animator -> Enemy_Idle state retains None for motion, and the second log shows Null. What am I missing? This is taken basically straight out of the first example in the AnimatorOverrideController docs.
     
  2. Kybernetik

    Kybernetik

    Joined:
    Jan 3, 2013
    Posts:
    2,470
    You're missing the fact that Animator Override Controllers were designed stupidly, just like the rest of the Animator Controller system.

    They override based on clip name, not state name. So you can't just have empty states, you need to assign default clips with unique names.

    Or you could check out Animancer (link in my signature) which lets you avoid Animator Controllers and just play whatever animations you want without wasting time worrying about overrides.
     
  3. BionicWombatGames

    BionicWombatGames

    Joined:
    Oct 5, 2020
    Posts:
    33
    @Kybernetik Thanks, I ended up realizing this too a few minutes after you posted, and yeah, my solution was to do like you said, create a bunch of empty placeholders and dump them in there in order to override them. This is all very unclear in the documentation, and questionably designed: if someone is making an Animator designed to be generic and overridden by various entities, why does it require existing clips to work?