I am playing around with animation blending and have an issue where my "throw" animation only gets played once, on the first button press, and never again after that. The "idle" and "walk" animations works perfectly. I have a feeling Im missing something really simple but cant seem to find it. Any help would be greatly appreciated. Here is my script : Code (csharp): public class CharacterAnimations : MonoBehaviour { private Vector3 velocity = Vector3.zero; private CharacterController controller; private AnimationState idleAnimation; private AnimationState walkAnimation; private AnimationState throwAnimation; private void Start() { controller = GetComponent(typeof(CharacterController)) as CharacterController; // Idle Animation idleAnimation = animation["idle"]; idleAnimation.layer = -2; idleAnimation.blendMode = AnimationBlendMode.Blend; idleAnimation.wrapMode = WrapMode.PingPong; idleAnimation.enabled = false; idleAnimation.weight = 1.0f; // Walk Animation walkAnimation = animation["walk"]; walkAnimation.layer = -1; walkAnimation.blendMode = AnimationBlendMode.Blend; walkAnimation.wrapMode = WrapMode.Loop; walkAnimation.enabled = false; walkAnimation.weight = 1.0f; // Throw Animation throwAnimation = animation["throw"]; throwAnimation.layer = 1; throwAnimation.blendMode = AnimationBlendMode.Blend; throwAnimation.wrapMode = WrapMode.Once; throwAnimation.enabled = false; throwAnimation.weight = 1.0f; throwAnimation.AddMixingTransform(transform.Find("Character_Root/Character_Spine")); animation.Stop(); animation.Play("idle"); } private void Update() { Vector3 velocity = controller.velocity; if (velocity != Vector3.zero) { animation.CrossFade("walk"); } else { animation.Blend("walk", 0.0f, 0.3f); } if ((Input.GetButtonDown("Attack")) (!animation.IsPlaying("throw"))) { animation.CrossFade("throw"); } } }
It would appear that I dont fully understand how animation weights and blending works. When I set the weight to 1.0f just before I call animation.CrossFade("throw") it works perfectly. Code (csharp): private void Update() { if ((Input.GetButtonDown("Attack")) (!animation.IsPlaying("throw"))) { throwAnimation.weight = 1.0f; animation.CrossFade("throw"); } } So an animaition looses it's weight after it has CrossFaded, even if it is set to WrapMode.Once? Anyone knows how it works?
You may verify the states of your animations using the debug mode in the inspector. You can also check AnimationsWatcher - a plug-in in the asset store that I've written to provide a more user friendly status of these animations