Dynamic Mecanim animation speed/time

Hi,

I’m currently working on implementing a weapons system, that features many different guns with different reload times and rates of fire. I need to shorten or lengthen character animations based to these weapon stats. Is there any way to dynamically alter the speed of animations from code in mecanim, or maybe just stop an animation state?

The workaround in this doesn’t apply in this case as far as I can tell. Any ideas?

The forum thread covers a couple different ideas. I’m not sure which one doesn’t apply. Here are some options to consider:

  • Set playback of the entire Animator using Animator.speed. Note that this overrides the speeds of all states in your controller. Probably not your best bet.
  • Set up different states using the same animation clip but with different speeds. Transition to the right state based on the current weapon.
  • Use a blend tree to blend between different versions of the same animation clip that are set to different speeds. This is a common solution to this problem, as you have very fine control of the speed.
  • (Undocumented and unsupported:) Dig into the internals of the controller: Getting a list of mecanim states in Animator - Unity Answers