Search Unity

Cannot cast RuntimeAnimatorController to AnimatorOverrideController

Discussion in 'Animation' started by HiteshSharma, May 3, 2017.

  1. HiteshSharma

    HiteshSharma

    Joined:
    Mar 24, 2014
    Posts:
    5
    I want to use AnimatorOverrideController to change the animation at run time through script. I tried this which gives and InvalidCastException:

    RuntimeAnimatorController controller = animator.runtimeAnimatorController;
    AnimatorOverrideController overrideController = (AnimatorOverrideController)controller;

    And this makes controller to null

    RuntimeAnimatorController controller = animator.runtimeAnimatorController;
    AnimatorOverrideController overrideController = controller as AnimatorOverrideController;

    That's what i found in all the code samples everywhere. Not sure what is going wrong here. I am using Unity 5.5
     
  2. stw-unity

    stw-unity

    Joined:
    May 1, 2017
    Posts:
    1
    You need to create a new AnimatorOverrideController, or use an AnimatorOverrideController asset, not cast your current AnimatorController to an AnimatorOverrideController.
     
  3. HiteshSharma

    HiteshSharma

    Joined:
    Mar 24, 2014
    Posts:
    5