Can someone please tell me why my animation script works for only certain models?

#pragma strict

var pauseAtBeginning : float;
var aWalk : AnimationState;
var aMelee : AnimationState;

function Start () {
	animation.playAutomatically = false;
	animation.Stop();
	
	aWalk = animation["walk"];
	if (!aWalk)
		Destroy (this.gameObject);
	
	aMelee = animation["melee"];
	if (!aMelee)
		Destroy (this.gameObject);
	
	aMelee.enabled = true;
	aWalk.enabled = true;
	animation.wrapMode = WrapMode.Loop;
	
	pauseAtBeginning = 2;
}

function Update () {
	if (pauseAtBeginning > 0) {
		animation.Stop();
		pauseAtBeginning -= Time.deltaTime;
		return;
	}
	animation.playAutomatically = false;
	
	aWalk.enabled = true;
	aWalk.layer = -1;
	aWalk.weight = 1;
	aMelee.enabled = true;
	aMelee.layer = 100;
	aMelee.weight = 1;
}

I attached this to two FBX models. One is a monster, and the other is a human. Both have their own animations, which have the same names in the FBX importer. They were exported from Blender with exactly the same settings, and both have animation compression turned off.

The monster executes its melee animation perfectly. It also walks, if I change the script to instruct it to do so.

The human ONLY executes the animation at the top of its list. So right now, it’s constantly walking, and ignores all commands to run the melee animation. I can change the speed of the walk animation, or stop/start it, but cannot execute any other animations.

Most of the solutions online suggest using animation.CrossFade(“melee”) or animation.Play(“melee”), but it does the same thing for me. They work for the monster, but not the human.

I immediately concluded that the human must have been incorrectly exported from Blender, but if I change the frame numbers for the first animation on her list (in Unity), I can make her play through any animation. Ergo, ALL keyframes are accounted for, and should be useable. So I CAN get that melee animation to work… as long as it’s the ONLY animation she uses.

I don’t know what’s wrong with this code. It’s incredibly simple, and works perfectly for the monster. Is there anything I’m missing here?

SOLVED

I had keyframes for bones that had been deleted, and also a pose-library. Upon removing both, the animations worked. Not sure why they partially worked in the first place, rather than completely not working, but it’s fixed!! I’m currently happily adding animations :smile: