Search Unity

'Animator is not playing an animator controller' error,even if there is an anim controller attached.

Discussion in 'Animation' started by Plusvalidx, Apr 24, 2022.

  1. Plusvalidx

    Plusvalidx

    Joined:
    Dec 7, 2021
    Posts:
    1
    Hello. I'm making a racing game for a project, and I was just implementing an item box. (It's not functional yet, so take it as if it was a random collectable)

    So, the idea is that if there's a a minimun distance between the box and the car, (that distance is stored on a variable I called 'distanciaObjetos'), then, the box should perform an anim called 'CogerCaja', which is only triggered if the parameter 'CogeObjeto' from the animator is set to truth. If the player reaches that minimun distance, the variable from the animator "CogeObjeto" is supposed to be set to true, so it can perform the animation 'CogerCaja' like this:

    Code (CSharp):
    1.  
    2. void Update()
    3.  {
    4.    distanciaObjetos = Vector3.Distance(transform.position, Item.transform.position);
    5.  
    6.     if (distanciaObjetos <= 60f)
    7.         {
    8.             CajaAnimator.SetBool("CogeObjeto", true);
    9.             //CajaAnimation.Play("CogerCaja");
    10.         }
    11.  }

    This line of code is written on my 'CarScript', so I have previously referenced the item box object, as well as its animator. This script is attached directly to the car, which is a prefab. (Since there are a lot of other cars that the player can choose.):

    Code (CSharp):
    1.  
    2. using System.Collections;
    3. using System.Collections.Generic;
    4. using UnityEngine;
    5.  
    6. public class CarCntroller : MonoBehaviour
    7.  
    8. //I have more variables, I'm just putting the ones that are more important to the case...
    9. public GameObject Item; //Here is the item gameObject.
    10. public Animator CajaAnimator; //Here I reference its animator.
    11. public float distanciaObjetos; //This variable will determine the distance between the car and the item box.
    12.  
    13. void Start()
    14.     {
    15.         //Same as above, I have more variables, I'm just putting the ones that are more important to the case...
    16.         Item = GameObject.Find("ItemBox");
    17.         Item.SetActive(true);
    18.         CajaAnimator = Item.GetComponent<Animator>();
    19.         CajaAnimator.enabled = true;
    20.     }
    21.  
    However, even if the theory is good, when my car comes near to the item box, it gives my a warning saying: "Animator is not playing an AnimatorController
    UnityEngine.Animator:SetBool(String, Boolean)"

    Now, to let you know that everything is properly attached, I will show you what I have in my unity project:

    Captura de pantalla (117)_LI.jpg


    As I said, the item box and its animator is attached to 'CarScript', so I can reference them. Everything shoudl work fine!:

    Captura de pantalla (118)_LI.jpg

    This error makes no sense, as everything is attached! It's also annoying, because this won't let me keep going on my project. What is happening, and how can I fix it?

    Here, I will put a more ordered version of my code:

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class CarCntroller : MonoBehaviour
    6. {
    7.   public GameObject Item;
    8.   public Animator CajaAnimator;
    9.   public float distanciaObjetos;
    10. }
    11.  
    12. void Start()
    13.  {
    14.    Item = GameObject.Find("ItemBox");
    15.    Item.SetActive(true);
    16.    CajaAnimator = Item.GetComponent<Animator>();
    17.    CajaAnimator.enabled = true;
    18.  }
    19.  
    20. void Update()
    21.  {
    22.    distanciaObjetos = Vector3.Distance(transform.position, Item.transform.position);
    23.    
    24.    if (distanciaObjetos <= 60f)
    25.       {
    26.          CajaAnimator.SetBool("CogeObjeto", true);
    27.          //CajaAnimation.Play("CogerCaja");
    28.       }
    29.   }
    30.  
     
    Last edited: Apr 24, 2022
  2. Unrighteouss

    Unrighteouss

    Joined:
    Apr 24, 2018
    Posts:
    599