Animation blending and/or activation problem

Hi there, new guy here, hehe :stuck_out_tongue: I’ve been having a hard time figuring this animation stuff out, and was wondering if I could get some help with it; particularly with the scripting.

The script in question:

private var bodyMove : AnimationState;
private var wingFlap : AnimationState;
private var headTwitch : AnimationState;
private var attack : AnimationState;
private var die : AnimationState;

function Start ()
{
   bodyMove = animation["bodyMove"];
   wingFlap = animation["wingFlap"];
   headTwitch = animation["headTwitch"];
   attack = animation["attack"];
   die = animation["die"];


   // animation layer setup
   bodyMove.layer = 1;
   wingFlap.layer = 0;
   headTwitch.layer = 1;
   attack.layer = 2;

   // configuring and starting up the animations
   
   animation["bodyMove"].wrapMode = WrapMode.Loop;
   animation.Play("bodyMove");

   animation["wingFlap"].wrapMode = WrapMode.Loop;
   animation.Play("wingFlap");

   animation["attack"].wrapMode = WrapMode.Once;
   
   animation["headTwitch"].wrapMode = WrapMode.Loop;
   headTwitch.blendMode = AnimationBlendMode.Additive;
   headTwitch.enabled = true;
   headTwitch.weight = 0.75;

}

function Update ()
{
	// Play the stinging animation whenever "T" is pressed.
	// (I created an input in the project settings 
	// called 'stab' which is activated by the T key)

	if (Input.GetButtonDown ("stab")) {
	animation.Play("attack");
	}
}

The thing being animated is a flying insect. The wingFlap animation is just that, his wings flapping, no other bones are touched. So that goes by itself, non-additively, and it plays with no problem. Then there’s the bodyMove, the insect bobs up and down, including his head, wings are not touched. This plays on the next layer. Again, so far no problem. Then there’s the the head twitch, added additively to the bodyMove’s animation layer, once again no trouble. All these loop constantly and compose the insect’s idle and basic movement.

Then we come to the problem; the attack animation. It plays on the next layer, non-additively but rather overriding the bodyMove animation, whenever the user presses the T key. Or at least, it’s supposed to. What happens is that the insect’s body movement animation gets completely halted for the duration the stinging motion is supposed to be, the stinging animation does not play, and then it resumes the body movement and goes back to normal. The wing flap, by the way, is unaffected, most likely because the other animations don’t use those bones at all.

But then, strangest of all, pressing T a second time yields the correct result! The body motion stops, the sting plays, and when the sting is done the body motion resumes as normal, and subsequent presses of T have it working perfectly.

It’s only that first time the T is pressed that it messes up, and this is where I’m getting confused. I’m sure it has something to do with the order in which stuff is being executed, but I’m unable to figure it out. Any help or advice on this (or perhaps a different, better method to do this) would be greatly appreciated. If any more info on what’s supposed to be happening is needed, please ask.[/code]

Hi - welcome to the forum!

Animation.Play can optionally take a second parameter specifying the play mode. The play mode defaults to stopping animations in the same layer before playing, but you can set it to stop other animations in all layers by setting it to StopAll. I’m not sure why only the first playback attempt fails, but using StopAll might fix the problem.

I’m having exactly the same problem with my first playback attempt failing but working properly the second time around. Did andeeee’s solution fix the issue for you?

Sadly, no :frowning: It just made my other added animations that are supposed to play constantly stop, so no go on that. I’ve had to move on to a different section of my project for now, so I haven’t found a way to get it working for sure yet; however I do have a guess as to what might get it going.

Rather than have my insect’s animations blended additively I’m going to go ahead and let them play over each other in layers, but restricting which bones are used via AddMixingTransform. I’ve gotten that to work on another character so I’m thinking this might be what fixes this one, but I’ll get back to you on it when I actually check.

Thanks for the response, Our programmer fixed our situation this morning :slight_smile:

I think in the end he had to rewind all the animations after they played so the next time around they would start from the right spot. he also said something about the blending type(?). He changed all of ours from “clamp” to “once” or “loop” and apparently that helped as well.