- Home /
Getting weird behaviour when blending animations of behaviour fields
I'm trying to animate fields in a few components that are children of my main object.
i.e. I have Hero, and under Hero there is a Sword which has a behaviour attached to it that changes texture based on a float field (textureIndex) it contains. Additionally, the player has a Shield set up in a similar way. Using the animation editor, I can create an animation clip that animates textureIndex, and is authored from the perspective of the hero (i.e. it animates the relative path ./Sword.Getcomponent.textureIndex. I author the clip for the Hero because I am using Animation Events to call functions on the hero when the animation finishes. I can then play the animation clip on the hero and see the textureIndex change (as well as seeing the texture change), in addition to receiving the animation events - wonderful!
The problem I am having is that If I try to play a similar animation clip which animates the shield's textureIndex, it will stop playing the clip that animates the sword.
Simple enough, I just need to call animation.Blend("ShieldAnim") rather than animation.Play("ShieldAnim"). This works fine the first time I call blend on a clip, but subsequent calls start behaving oddly. Sometimes it will play the animation twice in rapid succession, and I often times no longer receive the animation event.
Has anybody else run into this? Any advice? Right now I'm looking into writing my own animation system to bipass Unity's AnimationClip system, but I'd rather not go through that.
Thanks!
Answer by roamcel · Oct 08, 2011 at 07:03 AM
If I understood your problem correctly, you just have an animation layer problem, as in: animations need to exist in different layers if you need to blend them together, otherwise the last played one will override all the others.
$$anonymous$$y understanding is that if there are two blended animations in the same layer, and they have the same blend weight, they will each contribute 50%. This is also not ideal, since the two animations do not intersect - they animate totally different things. I want to play both animations with 100% weight each.
I misunderstood your comment. In order to run two non-intersecting animations at the same time, you don't need any special blending mode - neither Blend, nor Additive. Both give the incorrect result. All you need, as roamcel pointed out, is to put the two animations in separate layers and play them both. Thanks roamcel!