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. Join us on March 30, 2023, between 5 am & 1 pm EST, in the Performance Profiling Dev Blitz Day 2023 - Q&A forum and Discord where you can connect with our teams behind the Memory and CPU Profilers.
    Dismiss Notice

Help with issue with crossfade and animatorOverrideController!!!

Discussion in 'Animation' started by Tion-Gaming, Jun 6, 2019.

  1. Tion-Gaming


    Jan 30, 2015
    This has been a pain for so long. Basically imagine for simplicity i have one base layer for my walking and movment states, and another override layer with an empty default and a few states with animations. Desktop Screenshot 2019.06.06 -
    Simple enough right? (Btw this is an example project for showing the issue not my actuall) Now if i want to override the walking with an attack, for example, i crossfade to that state anytime i want. Its important that the animation clip can be changed for the state so i have an animatorOverrideController i create with a script. Changing the animatons via the script works great no issues at all. It works well even overriding other override states.

    Where the problems start is when you crossfade to one of the states you changed with the AOController while any other state is transitioning to empty what happens is it will transition from what seems to be the empty state if it had "Write Defaults" turned off to the desired state. instead of from its animation it was just in or the normal empty.
    Desktop Screenshot 2019.06.06 -
    This does not happen when the current state is transitioning to empty and you crossfade to a state that has not been changed by the animatorOverrideController. Here is the code for the simple script to reproduce the issue-
    Code (CSharp):
    1. //Public
    2.     public Animator animator;
    3.     public AnimationClip spinL;
    4.     //Private
    5.     private AnimatorOverrideController aOC;
    6.     private float testTO = 1;
    7.     private bool spin0 = true;
    9.     void Start() {
    10.         animator = transform.GetComponent<Animator>();
    11.         RuntimeAnimatorController myController = animator.runtimeAnimatorController;
    12.         aOC = new AnimatorOverrideController();
    13.         aOC.runtimeAnimatorController = myController;
    14.         animator.runtimeAnimatorController = aOC;
    15.     }
    17.     void Update() {
    18.         if (Input.GetKeyDown(KeyCode.T)) {
    19.             if (spin0) {
    20.                 aOC["SpinR0"] = spinL;
    21.                 animator.CrossFade("SpinR0", 0.1f);
    22.             } else {
    23.                 aOC["SpinR1"] = spinL;
    24.                 animator.CrossFade("SpinR1", 0.1f);
    25.             }
    26.             spin0 = !spin0;
    27.         }
    28.         if (Input.GetKeyDown(KeyCode.Y)) {
    29.             animator.CrossFade("New State", 1);
    30.         }
    31.     }
    Using it if you press "T" then "Y" then "T" again you can clearly see the issue reproduced.
    A video of the issue-

    Clearly what im doing is not common and ive searched for a long time for other people asking about this issue but have found no posts. Does anyone have a clue how i can fix this issue?
  2. Kybernetik


    Jan 3, 2013
    You might be interested in my Animancer plugin (link in my signature). It lets you avoid Animator Controllers and override controllers entirely, you can just play whatever AnimationClips you want and swap them out as needed. The Layers example should help with what you're trying to do.
  3. radiantboy


    Nov 21, 2012
    did you manage to solve this? im trying to do the same..