Search Unity

MissingComponentException: There is no 'Animator' attached to the "XXX" game object, but a scr

Discussion in 'Animation' started by C4D_Kristian, Jun 8, 2020.

  1. C4D_Kristian

    C4D_Kristian

    Joined:
    Apr 27, 2020
    Posts:
    3
    Hi folks,

    i made a little battleship game (with Monsters) and for animation i have a animator on each Cell with should start if there is a missed shoot (simple draw a black hole on the tile).

    Now i use the Gameobject name as a variable to select the right Gameobject and start the animation:
    Code (CSharp):
    1.             Debug.Log("Missed: "+ dragScript.targetArray[sliderXval,sliderYval]);
    2.             GameObject cell_hit = GameObject.Find(dragScript.targetArray[sliderXval,sliderYval]); //targetArray contains the Grid Field name
    3.             cell_hit.GetComponent <Animator>().SetBool("hit",true); // with this i get the error -> no Animator on Gameobject
    4.             Debug.Log(dragScript.targetArray[sliderXval,sliderYval]);
    5.             //grid90.GetComponent <Animator>().SetBool("hit",true); // with this and drag drop the GameObject in Inspector it is working
    With the 2 commands "gameobject.find" and Get Component Set Bool i receive the error:
    Which is strange since all cells have the same animator attached to their gameobject, and when i debugged it by selection the gameobject directly with the inspector -> it is working without problems.
    Code (CSharp):
    1. [SerializeField] GameObject grid90;

    btw. i searched for similar issues first and if i missed any information to help please give me a hint.

    Thanks
    Kristian
     
  2. C4D_Kristian

    C4D_Kristian

    Joined:
    Apr 27, 2020
    Posts:
    3