Animator is not playing an AnimatorController (Instantiated Prefab)

Dear Unity Community,
I’m struggling with the following problem:
I’m creating a quizapp (with the help of a tutorial on youtube: https://www.youtube.com/watch?v=HWCFJP6C4bk&t=3s)
So I wanted to extend the functionality with images/sprites. Images in questions work quite nice. But I also want to add pictures to a possible answer. Now I am at the Point, where I can not access the Animator inside the Answer Prefab. The following warning appears:

I set up the Animator correct. But my code can’t access the animator State.

answerImageStateParameterHash = Animator.StringToHash("AnswerImageState");
answerData.answerImageAnimator.SetInteger(answerImageStateParameterHash, 1);

As you can see I want to Call a ImageObject that is a Child of MyPrefab:

I already read about this problem, but can’t find a solution for myself. And I’m trying about 2 weeks to solve it…

My thought is that I need to Call the Animator, when the prefab is instantiated. But I couldn’t figure out how?

I hope that anyone can give me an solution or an advice how to handle this problem.

I have uploaded the scripts on Github. I hope this can give you an impression.
https://github.com/Gabo0890/QuizGame.git

Kind regards,
Gabriel




Alright, I solved the base problem.
The cause was in the function where the answers were instantiated.
I just use the following line:

answerPrefab.answerImageAnimator = newAnswer.GetComponentInChildren<Animator>();

However, i got a new “problem”.
The Animation is only working on the last clone of the prefab. the others are still in their default state. .
Does anyone has a suggestion, where the error could be caused?

Hello again,

I’m still struggling with this Problem. Only the last clone of the Prefab will be animated.

The first does not show any attached animator whereas the other does. However only the last one is the only to fully display the animation right.

Does this have anything to do with the part where the clones will be instantiated?

AnswerData newAnswer = (AnswerData)Instantiate(answerPrefab, uIElements.AnswersContentArea);
            newAnswer.UpdateData(question.Answers[i].Info, i);
         

            answerPrefab.answerImageAnimator = newAnswer.GetComponentInChildren<Animator>();

I hope anybody can help me to find a solution. I would really appreciate it!