Existing animations not found, even if found

Hi all

I have the weirdest problem you can imagine. I have (amongst others) an animation called “run” on a character. Doesn’t matter if I rename it to run, _run or Run it simply won’t play. I print a list of animations during runtime and it lists “run” as one of the animations it finds. if I then go Animation[“running”] I get a runtime error… Hell, even if I extract the name of the animation at that index and then pass that variable as the name of the animation to play, it tells me that animation does not exist. Let me just repeat that: I extract the name from the AnimationState and use the name I got FROM the animation to tell it to run the animation and it tells me the animation was not found.

All my other animations I tested one by one using the exact same code and all work… except for that one, no matter what I call it. Then I tried something really funky… I tried printing out the name of the animations and started adding @ symbols etc to the debug log statement and counting the length of the animation’s name to determine wether the name gets changed or something but nothing. Check this out…

function OnGUI()
{
  y = 0;
  for (var ast : AnimationState in Avatar.animation)
  {
    GUI.Label(Rect(400,((y++)*30)+10,300,25), "Animation "+y+ " = " + ast.name);
  }
}

So when I run my game, it prints run as one of the anims, right… but if I do this:

for (var s : AnimationState in Avatar.animation)
if (s.name == "run")
{
	Avatar.animation.CrossFade("run", 0.2);
}

It gives me a runtime error saying the animation I am trying to play does not exist but if I do this:

for (var s : AnimationState in Avatar.animation)
if (s.name.IndexOf("run") >= 0)
{
   Avatar.animation.CrossFade(s.name, 0.2);
}

it works just fine…I tried determining if the name gets changed somehow but Debug.Log(“@”+s.name+“@”) says otherwise… Totally strange but at least it works…

So, my code looks like this:

case eAnimState.Run :
	for (var s : AnimationState in Avatar.animation)
	if (s.name.IndexOf("run") >= 0)
	{
		Avatar.animation.CrossFade(s.name, 0.2);
	}
//	Avatar.animation["running"].speed = 1.0;
//	Avatar.animation.CrossFade("running", 0.2);
	break;
										
case eAnimState.Jumping :
	Avatar.animation.CrossFade("jump", 0.1);
	jumping = true;
  	break;
  					
case eAnimState.Punch :
	Avatar.animation["punch"].speed = 1.0;
	Avatar.animation.CrossFade("punch", 0.1);
	break;
  					
case eAnimState.Death :
	Avatar.animation["ko"].speed = 1.0;
	Avatar.animation.CrossFade("ko", 0.1);
	break;

Weird, right? But now yesterday I deleted all animations and started using motion animations so now I have completely new animations and a completely new problem… By inspecting the model in the scene, I see it has 5 animations but when I use the code above, it lists only 3. How is THAT possible? See the included screen shot.

So now my walk animation also doesn’t work because, although it is there, it isn’t found?!?!?!?!

case eAnimState.Walking :
//	Avatar.animation["femalewalk"].speed = 1.0;
//	Avatar.animation.CrossFade("femalewalk", 0.2);
	for (var s : AnimationState in Avatar.animation)
	if (s.name.IndexOf("femalewalk") >= 0)
	{
		Avatar.animation.CrossFade(s.name, 0.2);
	}
	break;

This causes the idle animation to play…

Please help!

671380--24088--$Screen Shot 2011-08-27 at 08.12.03.jpg
671380--24089--$Screen Shot 2011-08-27 at 08.18.40.jpg

To make matters even more confusing, when I just drop the prefab into a new scene, the script prints all animations but when I drop the character into a scene that I then load at runtime, the script prints only those three animations.

So my first thought was a that in some script, the animations are modified so I looked through all scripts in the project and I can’t find any animation init code of any kind. First I thought I’m simply missing something but then I looked again and I still can’t explain why what I see in the inspector and what I see onscreen doesn’t match. Not only does the inspector show 5 animations and the screen three, the order of the animations don’t match either… I simply cannot understand how the in-game animations doesn’t match the inspector values… Is it possible that Animationstate could be determining it’s values wrongly so it doesn’t match the animation clips???

More importantly than “why” is “how do I fix this?”

I actually managed to get this working.

Turns out that if I change stuff in the prefab, the instance APPEARS to have the same values but doesn’t. Dragging the instance onto the prefab changes nothing, but dropping a second instance of the prefab into the scene meant that one worked while the other one didn’t.

In the end, all I had to do was delete the instance in the scene and drop a fresh copy of the prefab into the scene and then Unity was able to use all the animations it listed in the inspector.