- Home /
Animation Blending Issue
So I'm having a bit of trouble with getting animations to blend together. Right now I'm blending the second animation like this:
animation.Blend("secondanimation", 1f, 0f);
animation["secondanimation"].blendMode = AnimationBlendMode.Additive;
This works really well, but when the first animation stops, the second one breaks outright. At the risk of overly simplifying the issue, is there an easy way to use additive blending for animations and not have them break when there are no normal animations playing?
Here's what happens right now: video. At 5 seconds, the second animation starts playing (the eyes move). At 11 seconds, the base animation stops. As you can see, it starts doing very strange things to the additive blended animation.
I'm not sure if I'm doing it wrong, or I'm missing something simple. There are a couple solutions that I could think of, like blending with an always running 'idle' animation, or keeping track of animations and shifting blending types, but neither sound like very good solutions. Are there any other ways to make it work well?
Answer by Owen-Reynolds · Jul 20, 2011 at 04:53 PM
The "always play looping base" seems to be the most official answer.
What I got from the big animation docs was to use layers to control combining/fading. Unity wants to play only 1/layer (CrossFade stops all on same layer. I think ani.Blend is a hack to break that rule.) The vanilla solution seems to be:
o Layer 0 (the default layer) has all of the "forever" animations, like a looping walk, run, dance, idle, 2-frame looping "frozen" to keep Add happy, falling... . You'll CrossFade into the new one, letting Unity automatically stop the old Layer0 one.
o Layer 2 (leaving layer 1 unused, just in case) has non-repeating animations, such as your entrance. Many of these will be some bones only (AddMixingTransform,) such as toss grenade. Some might be add animations. You can CrossFade these without thinking about the layer0 animation. Unity will auto-blend in and out for you.
o Layer 4 (saving layer 3 just in case) has all looping eyestalk animations, which will be either "eye bones only" or Adds
o Layer 5 has all non-looping eyestalk only, which can be played, will "cover" the looping eyestalks, but will revert back when done.
o Layer 6 has all front claws animations.
o etc...
So, play an actual knee-flexing idle (which is on L0) and CrossFade "entrance." Entrance wins (on L2, a higher layer,) but when it finishes, it autofades into looping knee-flex. That idle isn't just something to make Add happy -- you want it playing invisibly in the background, so you're auto-playing something after entrance finishes. In theory, Unity notices looping knee-flex is completely covered by entrance, so does no work computing anything for it until entrance ends.
Say you crossFade in the looping eyestalkWiggle after your 5 secs, but then you see a shark. All you do is CrossFade in eyestalkScared. That auto shuts off the eyeWiggle, but leaves entrance/idle unchanged.
Thanks for taking time to reply. The type of animation blending I plan on doing isn't really too complex, although using layers would probably help out a fair bit. I ended up using Blend for my test since it's the only one I got working, but using layers should work. When I tried it, it would just tend to overwrite the base animation or break, but I have a feeling I was just not using the correct combination of settings.
I guess in all cases though, I'll need a looping base in order to make proper use use of blending. Thanks for the help. :)
The three ways of "blending" are 1) Additive, which requires another, which may as well be looping; 2) real blend, by setting weight of upper to <1, which is pointless without a base, which may as well be looping, and 3) partial (Add$$anonymous$$ixingTransform,) which is fine with no base, but then the rest isn't moving, so why not have a base..
Your answer
Follow this Question
Related Questions
How Can I Get The Pants to Not Move? 4 Answers
Menu Movements 1 Answer
Making Character Stand? 1 Answer
Animation flashlight when run 4 Answers