- Home /
How to set animator's controller in script?
How to set animator's controller in script?
Answer by Radivarig · Oct 22, 2014 at 04:18 PM
Animator animator = playerTransform.gameObject.GetComponent<Animator>();
animator.runtimeAnimatorController = Resources.Load("path_to_your_controller") as RuntimeAnimatorController;
It's the path local to Resources folder. To load Assets/Resources/animator_controller.controller
the path is animator_controller
.
Answer by akash_virodhia · Aug 06, 2017 at 05:11 AM
public RuntimeAnimatorController anim2;
this.GetComponent().runtimeAnimatorController = anim2 as RuntimeAnimatorController;
Hope this helps
source:
https://forum.unity3d.com/threads/swapping-runtimeanimatorcontroller-during-runtime.368048/
Answer by Strangertoyourlife · Jul 27, 2019 at 12:40 PM
Way I found:
public Animator animator;
public RuntimeAnimatorController newController;
public void SetAnimator()
{
animator.runtimeAnimatorController = newController;
}
Answer by $$anonymous$$ · Feb 17, 2013 at 03:47 AM
Next time, check the scripting reference Here
No need to be so harsh, especially when the avatar and the controller aren't the same thing.
he is not being harsh, this answer is google-able.
not only the answer is not correct (it does not link to the correct document), generally Unity docs are very unhelpful. Assu$$anonymous$$g people first google and when for whatever reason they cannot find the answer they post here is a good start.
Your answer
![](https://koobas.hobune.stream/wayback/20220613092831im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Applying animation to character not working 0 Answers
Reusing animations 0 Answers
How can I set the avatar in the animator at runtime? 1 Answer