- Home /
How to Access AnimaionState in Mecanim?
Hi, I'm using Mecanim Animation System in Unity 4.5.x. I have an Animator component on a GameObject called "VictorSprite", with several layers, each layer has several AnimationStates.
How can I access each AnimationState to change its properties, specifically speed?
Unfortunately, most of the documents I can find are deprecated, and don't refer to Mecanim. I have also tried this code:
AnimationState animState = GameObject.Find("VictorSprite").GetComponent<Animator>().animation["VictorTalk"];
But, I receive this error message: "MissingComponentException: There is no 'Animation' attached to the "VictorSprite" game object, but a script is trying to access it. You probably need to add a Animation to the game object "VictorSprite". Or your script needs to check if the component is attached before using it."
Adding Animation component is not recommended anymore in Unity 4.x.
Could anyone help please?
Answer by Tanshaydar · Nov 02, 2014 at 05:20 PM
Animator -> Mecanim Animation -> Legacy Animation system So in your case, I'm not sure you can access your animation state with this code.
I use AnimatorStateInfo
which gives me animator state in Mecanim:
private AnimatorStateInfo currentBaseState;
...
currentBaseState = animator.GetCurrentAnimatorStateInfo(0);
0 here is the layer, usually it is Base Layer and given is zero.
Thanks for the reply, I have tried AnimatorStateInfo too, but as you can see in this page (http://docs.unity3d.com/ScriptReference/AnimatorStateInfo.html), there are not fields like speed, o wrap$$anonymous$$ode in this class! :-(
Any Idea?