Search Unity

Animator is not playing an AnimatorController

Discussion in 'Cinemachine' started by Shizola, Aug 9, 2017.

  1. Shizola

    Shizola

    Joined:
    Jun 29, 2014
    Posts:
    475
    Tried out the state driven camera and to control it I thought it would be neater to just attach an animator rather than have it on a separate gameobject. If you do this you get a "Animator is not playing an AnimatorController" warning every time you select a camera. Not a big deal but I thought it was a bug or there is a reason why you shouldn't do it this way. P.s Loving Cinemachine so far!

    Edit - Actually it seems like I'm getting spammed whether it's on a separate object or not. .
     
    Last edited: Aug 9, 2017
  2. Whatever560

    Whatever560

    Joined:
    Jan 5, 2016
    Posts:
    515
    Facing the same issue, it seems the cinemachine is not working with an override controller, no layers are shown, when I switch to the base controller it works perfectly.

    With the basic normal controller, layers
    upload_2017-8-10_12-52-57.png

    With an override controller on the target, no layer and warning "Animator is not playing an AnimatorController"
    upload_2017-8-10_12-51-32.png
     
    Last edited: Aug 11, 2017
  3. Whatever560

    Whatever560

    Joined:
    Jan 5, 2016
    Posts:
    515
    Its seems like a design/implementation flaw with RuntimeAnimatorController and AnimatorController/AnimatorOverrideController.
    Accessors should be more generically placed in RuntimeAnimatorController, it's not the first time I step on an issue with override controllers
    My 2 cents fix to make it work, at least in the editor, don't know if there will be side effects


    replace in CinemachineStateDrivenCamera from line 320

    with
    Code (CSharp):
    1.  public static AnimatorController GetControllerFromAnimator(Animator animator)
    2.         {
    3.          
    4.             var overrideController = animator.runtimeAnimatorController as AnimatorOverrideController;
    5.             if (overrideController)
    6.             {
    7.                 var animatorController =
    8.                     overrideController.runtimeAnimatorController as AnimatorController; //dirty as hell
    9.                 return animatorController;
    10.             }
    11.  
    12.             return animator.runtimeAnimatorController as AnimatorController;
    13.         }
    14.  
    15.         private CinemachineVirtualCameraBase ChooseCurrentCamera(float deltaTime)
    16.         {
    17.             if (m_ChildCameras == null || m_ChildCameras.Length == 0)
    18.             {
    19.                 mActivationTime = 0;
    20.                 return null;
    21.             }
    22.          
    23.             int layerCount = GetControllerFromAnimator(m_AnimatedTarget).layers.Length;
    24.          
    25.             CinemachineVirtualCameraBase defaultCam = m_ChildCameras[0];
    26.             if (m_AnimatedTarget == null || m_LayerIndex < 0 || m_LayerIndex >= layerCount)
    27.             {
    28.                 mActivationTime = 0;
    29.                 return defaultCam;
    30.             }
    replace in CinemachineStateDrivenCameraEditor
    Code (CSharp):
    1.         private void UpdateTargetStates()
    2.         {
    3.             // Scrape the Animator Controller for states
    4.             AnimatorController ac = (Target.m_AnimatedTarget == null)
    5.                 ? null : Target.m_AnimatedTarget.runtimeAnimatorController as AnimatorController;
    with

    Code (CSharp):
    1. private void UpdateTargetStates()
    2.         {
    3.             // Scrape the Animator Controller for states
    4.             AnimatorController ac = (Target.m_AnimatedTarget == null)
    5.                 ? null : CinemachineStateDrivenCamera.GetControllerFromAnimator(Target.m_AnimatedTarget);
     
  4. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,711
    @Whatever560 Thanks for the excellent detective work! Would you mind uploading a small test project that shows this?
     
  5. Whatever560

    Whatever560

    Joined:
    Jan 5, 2016
    Posts:
    515
    Sorry won't have time for that right now ... do you have any github/bitbucket for cinemachine ?

    Though I really think it should be resolved between RuntimeAnimatorController (add there "layers" access) and AnimatorController/overrideController impl.

    Could be done in 2 lines without breaking any API will remove the dirty trick and avoid unpredictably having to cast the controller to access layers.

    (BTW - When is Unity coming to open source to allow push request and correcting everything more quickly ? You have a damn community of devs waiting for that :D, it will definitely bring the engine to a more professional/industrial level )

    Best
     
  6. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,711
    @Whatever560 @Shizola We don't believe it is a CM problem, and are unable to reproduce the effect here. A repro project would definitely help the animation team resolve this. Unfortunately your fix will not work in runtime/standalone.