- Home /
Invalid Layer Index on mecanim animator
Hi guys, we've been crushing the heads on a wall for 3 days for this problem. I have a prefab instantiated several times by a script in the game scene. The prefab is composed by 2 objects, one inside the other. The Main_object and the inside_one. The inside_one has got an animator. It works perfectly for a month. We introduce a Network system, and it continue to works fine. 3 days ago the animator system starts to go mad (and we follow). I know is not professional to say something like this but situation is very strange: the inside_one has got a Animator component witch its Contoller is called Card_animator_controller and has got two layers and 8 parameters. In a script linked to the Main_object we use:
public Animator anim;
anim = transform.FindChild("inside_one").GetComponent<Animator>();
if (anim) //we put this just to be sure
Debug.Log ("Animator Exists!");
Debug.Log ("anim controller: " + anim.runtimeAnimatorController.name);
Debug.Log ("anim num of layers: " + anim.layerCount);
anim.SetInteger("NameOfTheParameters", 0);
AnimatorStateInfo infoAboutAniamtor = anim.GetCurrentAnimatorStateInfo(0);
these debugs produce this output:
"Animator exists!"
"anim controller: Card_animator_controller."
"anim num of layers: 0" (what?)
Waring: Parameter 'NameOfTheParameters' does not exist. (what!?)
Error: Invalid Layer Index (WHAT!?)
this is a snapshot of the Card_animator_controller:
Any help would be grat! Thanks
Answer by AbePoppy · Nov 29, 2013 at 04:58 PM
Something of more interesting: we open a new project, then we open the previous project and everything start again to work properly... O.O
how... what... but above all: why!?
Answer by DarJam · Dec 10, 2013 at 07:05 PM
Thanks for the suggestion AbePoppy. Exiting Unity and reloading the project worked for me.
Due to all the problems with Unity/Maverick, my machine froze for 3+ mins and so i powered down my iMac whilst Unity was in Play mode. I reckon this act probably caused the problem.
Anyway thanks
Answer by RKSandswept · Feb 16, 2014 at 08:41 AM
We had a similar problem. Switching project over and back did not solve it.
Turns out the GameObject (third person player avatar) with an animator was disabled at start up and then enabled later when the game is running. It appears that having the third person player avatar (over the shoulder view only)disabled makes the animator not get loaded or generated correctly.
Also the problem only showed up in the both a final and a debug build, but not in the debugger.
To fix this we enabled the whole third person player avatar during the build and then disabled it after start up.
This is probably an effect of the build removing any assets that are not used in the game, and the disable third person player avatar appeared to be 'not used' yet is a child GameObject of our overall player GameObject.
Answer by trololo · Oct 07, 2014 at 01:47 PM
AbePoppy, did you find a better way to handle that problem? (i got exactly the same one...).
Sorry for the late answer. Yes, using the new version of Unity the problem magically disappear XD
Your answer
![](https://koobas.hobune.stream/wayback/20220613123051im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Can you change AnimationClip in controller via scripting? 0 Answers
How to disable/override a part of an animation created in Unity 2017.4 0 Answers
Trying to use Mechanim Root Motion for 2d. 0 Answers
I can preview the animation but in scene it doesn't work 0 Answers
"GravityWeight" curve in animator is not affecting the rigidbody's gravity? 1 Answer