animation.play("walk") vs animation[walk]

I’m having trouble understanding the docs for animation as a component vs. animationState

Does
animation.Play() play whatever animation states are enabled?

If I want to call the walk animation I can use
animation.Play(“walk”);?
but what will happen if two other animation states enabled and weighted at 1.0?
then what does animation.Play(“walk”) do now?

animation[“jump”].enabled
animation[“walk”].enabled

this is very confusing.

Dan

animation.Play() will play the default clip of an animation component. You should really never use this unless your gameObject has only one animation.

animation.Play(“idle”) would play the animation named “idle” from the beginning if it isn’t playing already. If its already playing, telling it to play again does nothing. Playing an animation in this way overrides any other animation playing in its layer if they all have weights of 1.

Something to note is that simply telling an animationState to be “enabled” doesn’t do anything by itself. Personally I never alter or check an animation’s “enabled” flag, I just use animation.Play(“name”) or animation.CrossFade(“name”) to trigger animations. In the event that you want to mix multiple animations, you’d use layers, weights, and mixingTransforms, but the normal behavior is that playing one animation with a weight of 1 stops all the others in its layer.

If you’re getting unusual results, check our clips’ wrapmodes as well, as the wrong one for the wrong situation can cause unpleasant results.

One last tip - set all of your animationState setup in an awake function or something, so you can initialize all of the layers, weights, speeds, wrapmodes etc. of all of your clips once at startup.