Animation Controller API

Hi, i want to ask something about animator / animation controller in unity.

  1. **is there any method to set/assign an animation to an animator state ?
  2. is there any method to assign default state programatically like “set as default” from animator window**

i already search about this topic but seems there’s no one yet explain it.

thanks before :slight_smile:

1: If you’re talking programatically, no, not as far as I know. You might be able to hack your way in through reflection, but you probably shouldn’t.

2: No

Both of these things might change with Unity 5, but probably not.

Usually, when people ask 2, it’s because they want the model to spawn in a certain animation pose that’s not the default one. If you’re doing that, you’ll want to hide the spawned object for one frame, use CrossFade with 0 as the transitionDuration parameter, and then make the object visible.

For 1. that would probably be a bad idea. If you need to change what animations your animator controller is using, and you’re changing more than 1, make a different controller with the same parameters. If it’s just one or two states that differ, just make it work with different states.