Search Unity

Help with issue with crossfade and animatorOverrideController!!!

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

  1. Tion-Gaming

    Tion-Gaming

    Joined:
    Jan 30, 2015
    Posts:
    2
    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 - 05.58.51.53.png
    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 - 06.09.38.100.png
    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;
    8.  
    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.     }
    16.    
    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

    Kybernetik

    Joined:
    Jan 3, 2013
    Posts:
    519
    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.