Animation Blending Issue

I’m having an issue with getting animation blending to work (or not work).

I have a character model with an idle animation and a walk animation. The model was created and animated in Maya. The animations work fine in Unity and play as expected.

However, I am having a serious issue transitioning from the [idle] to the [walk] animation.
I require [idle] to loop constantly until movement starts and then to transition from [idle] to [walk] and loop the [walk] animation once movement is detected. The problem I am having is that when the [walk] animation starts, the positions of the character’s arms remain where they were during the [idle] animation when it stopped (the feet and head animate as expected).

I have tried using CrossFade, Play, CrossFadeQueued, Changing blend weights, Stopping previous animations before starting the next, resetting animation positions, etc, but can’t seem to find a way to even just “reset” the arm positions before starting the walk (let alone transition smoothly between them). It appears that the animations are blending (with the walk only affecting the legs and head of the model) when I do not wish them to.

The important part of my code is below:

function Start()
{
   /* I have tried WrapMode.Loop too */
   animation["idle"].wrapMode = WrapMode.Once; 
   animation["walk"].wrapMode = WrapMode.Once;
}


function Update()
{
	if(targetSpeed != 0)
	   animation.Play("walk");
	else
       animation.Play("idle");
}

Any help would be appreciated and I apologise if this is a frequent/silly question.

EDIT: Error appears to be a specific animation issue and not a unity issue.

Are you sure that Walk plays the arms? Try just animation.Play("walk") in Start, nothing else. You’re describing exactly what would happen if walk were missing the arm bones.

For some imports, in the big animation list through the Inspector, I get duplicate animations. All but one plays various subsets of bones, and I have to trial&error the correct one. I’ve had it where Default was walk, but animation[2] in the list was the “other”, wrong walk.

Also, Loop is correct (but since you’re constantly running Play, your current code turns playOnce into Loop.)

Yes – an extra bone in idle would make it appear to break other animations. From Unity’s point of view, every other animation is the problem, for not including that bone.

What happens is: idle rotates all bones, including mystery shoulder bone. For Walk, Unity thinks missing a bone is a specific instruction to leave that bone where it was. So, as idle crossfades into walk, mystery shoulder bone has no target in walk, so plays as in idle. When idle stops, mystery shoulder bone no has no target anywhere, so stays in that odd rotation.

I wouldn’t be too hard on the animator. Most of them have only done things completely inside Max or Maya, where the rules are different. My kids sometimes export a model which looks really wrong, and I try to explain that it’s in “rest pos”, with no animations, and they’ve baked some scaling/rotations into the animation by mistake. The thing is, Max never wants to show you “rest pos,” so they don’t even know what I’m talking about.

Saying “every animation must include every bone” will probably solve a lot of problems (and you can “remove” bones from animations later, in Unity.)

You can move a bone yourself – it’s just a Transform (untested):

Transform B = transform.Find("body/spine/shoulder/idleShoulderhackBone");
Quaternion BstartRot = B.rotation;

if(gettingOutOfIdle) {
  B.rotation = Quaternion.RotateTowards(B, BstartRot, 3);
  if(B.rotation == BstartRot) gettingOutOfIdle=false;
}