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 have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

GetEffectiveAnimatorController() - Unity 5 alternative?

Discussion in 'Animation' started by hammil, Mar 5, 2015.

  1. hammil

    hammil

    Joined:
    Jun 5, 2013
    Posts:
    56
    Previously I was using this line to get the AnimatorController for a given Animator

    Code (csharp):
    1. var controller = AnimatorController.GetEffectiveAnimatorController(animator);
    However this no longer works in Unity 5. There's a method to set the controller, as shown in the API docs, but not one to get it.
     
  2. Mecanim-Dev

    Mecanim-Dev

    Unity Technologies

    Joined:
    Nov 26, 2012
    Posts:
    1,675
    Effectively the function was marked internal in 5.0

    I will investigate what did happen.

    In the meantime you can use this function to do the same thing

    Code (CSharp):
    1.    
    2. RuntimeAnimatorController GetEffectiveController(Animator animator)
    3.     {
    4.         RuntimeAnimatorController controller = animator.runtimeAnimatorController;
    5.  
    6.         AnimatorOverrideController overrideController = controller as AnimatorOverrideController;
    7.         while (overrideController != null)
    8.         {
    9.             controller = overrideController.runtimeAnimatorController;
    10.             overrideController = controller as AnimatorOverrideController;
    11.         }
    12.  
    13.         return controller;
    14.     }
     
    hammil likes this.
  3. hammil

    hammil

    Joined:
    Jun 5, 2013
    Posts:
    56
    That's wonderful, thank you!
     
  4. mk26

    mk26

    Joined:
    Dec 2, 2014
    Posts:
    5
    That's fabulous.

    But in my case, i want the alternate of this
    Code (CSharp):
    1.  
    2. usingUnityEditor.Animations;
    3.  
    4. [CustomEditor(typeof(uLinkAnimator))]
    5. public class MyAnimatorEditor : Editor
    6. {
    7.     private AnimatorController m_Controller;
    8.  
    9.    void OnEnable() {
    10.       this.m_Controller = GetEffectiveController(this.m_Animator);
    11.    }
    12. }
    13.  
    As, this is not working in Unity 5. And not found any solution to get the AnimatorController from the Animator in Editor scripting.
     
    Last edited: Jul 12, 2016
  5. belly82

    belly82

    Joined:
    Aug 11, 2016
    Posts:
    1
    Thank you. I was looking for same exact solution for this problem. Thanks alot.
     
    Last edited: Sep 13, 2016
  6. Diet-Chugg

    Diet-Chugg

    Joined:
    Jul 4, 2012
    Posts:
    51
    I'm having the same problem as mk26
     
  7. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    6,199
    AnimatorController inherits from RuntimeAnimatorController. At edit time, .runtimeAnimatorController is the actual AnimatorController.


    This is not documented. The naming of these things are not intuitive whatsoever.