- Home /
Quick additive animations with Mecanim
I am trying to do a quick punching animation for my character using the new Mecanim system. I watched the video tutorial with the hand waving, but the wave animation is much slower and can blend better. There is an "override" option for the layer that you can set in the controller(instead of additive), but that doesn't seem to help. Is there something in the animation settings that will kill the transition between states and make the weight go straight to 1?
thanks for you help. Scott
Answer by webNeophyte · Dec 13, 2012 at 03:58 AM
I figured it out. The issue has to do with a layer property in mecanim called "weight". It controls the blending weight for the entire layer. When you create a layer in Mecanim, it defaults to 0 (no influence). You have to manually change it via script if you want it to play.
animator.SetLayerWeight( 1, 1.0f );
"animator" is an instance of the Animator class that your character uses. It grabs the layer (first parameter) and sets the weight (second parameter).
http://docs.unity3d.com/Documentation/ScriptReference/Animator.SetLayerWeight.html
[1]: http://docs.unity3d.com/Documentation/ScriptReference/Animator.SetLayerWeight.html
Thanks for sorting this out!
In my case, however, the weight of a new layer always seems to default to 1 ins$$anonymous$$d of 0. Can you tell us the unity version with which you've tried this?
I only asking this because my additive animation layer in mecanim doesn't play at all (even with weight = 1), no matter what I do. So I am wondering whether the problem/solution decribed here matches my own problem.
Thanks alot!
I am using some flavor of Unity 4.0. Can't remember the $$anonymous$$or version number at the time. Right now I am in 4.0.0f7.
For your problem, I would first check out the animation to make sure it imported correctly in Unity. For testing $$anonymous$$ecanim stuff, I usually keep the Animator window open to see which animation states are firing off when ( Windows > Animator). Also you could try setting the other layers to 0 weight to see if that makes a difference.
Thanks for your reply, webNeophyte!
I am using some flavor of Unity 4.0. Can't remember the $$anonymous$$or version number at the time. Right now I am in 4.0.0f7.
Alright, it's the same for me. So we're talking about the same version.
For your problem, I would first check out the animation to make sure it imported correctly in Unity. For testing $$anonymous$$ecanim stuff, I usually keep the Animator window open to see which animation states are firing off when ( Windows > Animator).
I guess that I've checked all of this, but I remember that the animation states in the animator preview window seem to be stuck somehow, which indicates that there might be something corrupt. Definitely worth checking this first.
Also you could try setting the other layers to 0 weight to see if that makes a difference.
That's a really good idea that didn't come to my $$anonymous$$d so far! Will try to have a look at this! Thx.
I was struggling with the same problem. The weight in the Animator for my second layer was set to 1, but the animations never played.
I added
animator.SetLayerWeight(1, 1);
in Start() and then it worked. So I'm guessing even though the Animator windows shows the weight is 1, it gets reset to 0 when you start your game.
Yes, I can also confirm this. I did it slightly differently, but with the same (positive) effect:
animator.SetLayerWeight(0,0);
animator.SetLayerWeight(1,1);
This makes both of my layers work perfectly. From what nielsvaes posted, I learned that I can omit my first line of code. And, of course, I also had to ensure that the same is applied to any other additional layer. Hence in my case (with one Base Layer and 4 extra layers) the working solution looks like this:
//animator.SetLayerWeight(0,1); // unnecessary!
animator.SetLayerWeight(1,1);
animator.SetLayerWeight(2,1);
animator.SetLayerWeight(3,1);
animator.SetLayerWeight(4,1);
Your answer
Follow this Question
Related Questions
Mecanim additive animation sends characters flying? 1 Answer
Reference clip for Additive blending animation in Mecanim 0 Answers
How to combine mecanim and script based bone movement/animations? 2 Answers
Custom unity Animation wont work properly (adding avatar to animation?) 0 Answers
Animation Events and Mecanim 0 Answers