- Home /
Changing Animator Controller Animations Via Script
If I have multiple game characters that all have the same types of animations (idle, walking, jumping) and each one has different animations (HumanIdle, HumanWalk, MonsterIdle, MonsterWalk, etc), do I need to create a separate Animation Controller for each of them, or is there a way to create one Animation Controller with Idle, Walk and Jump states defined, but with the actual animations they point to being changed programatically?
Answer by Jason2014 · May 05, 2016 at 07:52 AM
You are creating one Animator Controller, to control all of them. I don't know if you are creating a 2D or 3D game, because they have much difference in configuration. Have you heard about "Blend Tree"?
This special feature allows to control all of animations in one. For script control you have to add parameters in animator first and then by scripting you need to change values. This is too complicated to explain in answer, so check this videos: Player Animator Controller
and this: Writing the Player Script
I'm creating a 2D game, and I've been using that roguelike tutorial for reference, but it also highlights the issue; different animation controllers were made for both the player and the enemies, even though many animations were shared between them (PlayerIdle, EnemyIdle, Enemy1Idle are all "idle animations").
$$anonymous$$y goal is to ideally have just one AnimationController and then, say, in the Player's script say "the Player GameObject's AnimationController's idle animation is PlayerIdle, moving animation is PlayerWalk, etc."
Answer by plagas36 · May 12, 2016 at 02:51 PM
I think you'll have to create multiple animator controller.
I've just made exactly what you need. I got the same problem a few days ago.
Check out this asset : Example
Also, it can do a lot more than that. It can copy curves and events that you've put on an clip on another one. Perfect if some of your characters get the same events and cuves for the same kind of animations.
I show an example here : Example