Search Unity

  1. Unity 2019.2 is now released.
    Dismiss Notice

Animation Override Controller asset use / swap at runtime

Discussion in 'Animation' started by BenbowNvizzio, Jan 18, 2018.

  1. BenbowNvizzio

    BenbowNvizzio

    Joined:
    Apr 19, 2017
    Posts:
    3
    Hello,
    i'm trying to use animation override controller via the asset created through editor.
    I've created a bunch of them, linked them as reference on my GameObject.

    Now i'm trying to swap them at runtime using the the one that i saved, and the override are never applied.

    here's my code

    Code (CSharp):
    1.  
    2. //Reset to not override controller
    3. AnimatorOverrideController myOverrideController = animator.runtimeAnimatorController as AnimatorOverrideController;
    4. if (myOverrideController != null)
    5. {
    6.     animator.runtimeAnimatorController = myOverrideController.runtimeAnimatorController;
    7. }
    8.  
    9. //create new Controller
    10. var animatorOverrideController = new AnimatorOverrideController(animator.runtimeAnimatorController);
    11. animator.runtimeAnimatorController = animatorOverrideController;
    12.  
    13. //fill new override with data
    14. var dataOverride = this.RodOverrideController;
    15.  
    16. var overrides = new List<KeyValuePair<AnimationClip, AnimationClip>>(dataOverride.overridesCount);
    17. dataOverride.GetOverrides(overrides);
    18.  
    19. //Apply it
    20. animatorOverrideController.ApplyOverrides(overrides);
    21.  
    i don't understand, even if it's not present at all anywhere in the internet, why this does not work either :

    Code (CSharp):
    1.  
    2. animator.runtimeAnimatorController = this.RodOverrideController;
    3.  
    i'm on unity 2017 1.1p2

    Thanks