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. We’re making changes to the Unity Runtime Fee pricing policy that we announced on September 12th. Access our latest thread for more information!
    Dismiss Notice
  3. Dismiss Notice

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