what's the best way to change animators on a player, in script?

In my test scene I have a character who I want to switch animator controllers whenever I press a button.
For example from rifle to handgun. What’s the easiest and least performance hitting way to do this?


Get the animator component on the object and a reference to the animators you plan to use, and change the current animator controller using the runtimeAnimatorController property: Unity - Scripting API: Animator.runtimeAnimatorController

Also, “least performance hitting”? How many times per second will you switch the animator controller? Hits in performance come from things you do really often or things that needs a lot of processing. I’m not even sure if there are other ways to change the animator controller (it’s the only public property to access it), but if there are, you shouldn’t worry a lot on the performance of the methods.