RuntimeAnimatorController not loading from script

Hi, I have a problem when loading a RuntimeAnimatorController from the script. I have been looking throug any avialable forum or tutorial on internet but I still haven’t found the solution.

public RuntimeAnimatorController animSit;

    public void animar(GameObject paciente)
    {
        Animator sentado = paciente.GetComponent<Animator>();
        //sentado.runtimeAnimatorController = Resources.Load("Assets/animControl/H_B_obeso_contr") as RuntimeAnimatorController;
        sentado.runtimeAnimatorController = animSit;
    }

Both of the ways I’m trying to add the AnimatorController doesn’t work. It keeps the AnimatorController in blank.

78158-captura.jpg

If during runtime I add the Controller through the Inspector, it works!!
but I need to add it from the script because I’m instantiating the GameObject.

I really apreciate if you have any kind of solution, been trying to solve this for a long time.

I don’t agree with “Best Answer”.

Currently I’m on latest beta 2018.2.0b9 Personal and here’s what could be the root cause:
If my RuntimeAnimatorController is not placed in \Resources\ folder script will behave just like in your situation - no errors, no warning and if you select animator in inspector it still “None”. BUT! After i placed RuntimeAnimatorController in \Resources\ everything started working.

Summary:

Step 1:
Place RuntimeAnimatorController into \Resources\ folder. Lets say file name will be “MyController.controller”.

Step 2:

var animator = gameObject.AddComponent<Animator>();
animator.runtimeAnimatorController = Resources.Load<RuntimeAnimatorController>("MyController");

After many tries, the answer is simple.

By this version of Unity, there is an obligation where you have always to set the controller before you run the scene. It is impossible to add the controller to the RunTimeAnimatorController without a a controller.

Just answering myself because if someone have the same answer.

Hi, I´m with the same problem now. So how could I set the controller before run the scene.

Hi there. I’m not sure if anybody is still having trouble with this. I think I have accomplished what what it was you were trying to do. Basically, I set up an Animator on my character, and then a set of SerializedObject’s to hold the different RuntimeAnimiatorControllers I wanted to switch to. Then, at the appropriate time, I ran this basic code:

RuntimeAnimatorcontroller motionAnimator; // set up previously
// store the previous controller
originalAnimator = myController.myAnim.runtimeAnimatorController;
// change the runtimeAnimatorController on the Animator to the new controller
myController.myAnim.runtimeAnimatorController = motionAnimator;

That all worked for me as far as changing controllers when I wanted it to. However, once I got it to work, the problem then became smoothly animating between controllers. it got very jumpy. I’m now in the process of refactoring all of that out, and auto generating my AnimatorController based on some chosen sub state machines. But the switching did work.