How to add an animator controller to an animator Component (c#)

So I was setting up an animator and everything was going nicely:

playerAnimator = playerModel.GetComponent<Animator>();
playerAnimator.animatePhysics = true;

Then I tried to setup the Animator Controller but things went wrong, it seems the animator doesn’t have a controller variable or method:

http://docs.unity3d.com/Documentation/ScriptReference/Animator.html

Is this a bug or I missed something ? My character will never work without a controller :frowning:

Have your tried to set Animator.runtimeAnimatorController?

It looks like the Animator’s Controller property is private set, so you won’t be able to change it via script. Until Unity decides to change that (if they ever do), maybe you can work around this by assigning via the editor your controller into a prefab, and then using Resources.Load() to get an instance of the GameObject:

// Instantiates a prefab at the path "Assets/Resources/myPrefab".
GameObject myInstance = Resources.Load("myPrefab") as GameObject;

I’ve just successfully done this in an Editor script. You need to add a RuntimeAnimatorController to the Animator component of the GameObject:

GameObject.FindGameObjectWithTag("Player").GetComponent<Animator>().runtimeAnimatorController = newAnimationController;