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!