Assigning runtime animator controller to animator via script

Hi,

I am trying to assign an existing RuntimeAnimatorController to a GameObjects Animator out of my assets but it never works…

...

        GameObject obj_Character = Instantiate(InstantiateCharacter, new Vector3(0, 0, 0), Quaternion.identity) as GameObject;
        Animator obj_Character_Animator = obj_Character.GetComponent<Animator>();
        obj_Character_Animator.runtimeAnimatorController = (RuntimeAnimatorController)Resources.Load("PlayerController", typeof(RuntimeAnimatorController)) as RuntimeAnimatorController;

...

I tried every possibility, but nothing seems to work. The Animator’s runtime Animator Controller field stays empty.

I hope you can give me advice!

Animator animator = playerTransform.gameObject.GetComponent<Animator>();
animator.runtimeAnimatorController = Resources.Load("path_to_your_controller") as RuntimeAnimatorController;

as given by @Radivarig on this question

1 Like

@UnSpotibleShadow have allready tried that (like my code above, without (RuntimeAnimatorController) and typeof definition) - didn’t work.

1 Like

no typos in the name and the controller is in the Resources?

this question is actually doing me headin… no errors being thrown by unity?

@UnSpotibleShadow yes the resource is in the assets with exactly the name of. Tried without typof and unity don’t throw any errors. the method Resources.Load(… never ever delivers something back. Have the resources to be in a special folder in the assets, no or?

No the Resources folder should just be under Assets.

Oh man! There have to be a folder named “Resources” and all your assets you like to load with Resources.Load have to be placed there! OK just that way it works!

Thank you UnSpotibleShadow! You saved my day!

1 Like

Haha yea! Glad I could help you out!

1 Like

I did in same way, but it is still not working
Please help me…