[Question] RuntimeAnimatorController

So I’m trying to setup a way to change the players Animator Controller. Googling led me to do the following:

void Start ()
    {
        myAnim = GetComponent<Animator>();
    }
    public void SwapCharacterProc()
    {
        myAnim.runtimeAnimatorController = Resources.Load("Assets/Animations/Player/ArcherFemale/Player_Archer_Female") as RuntimeAnimatorController;
   
   
    }

I believe the pathing is correct because I double checked it here:

So in another .cs I’m trying to call this proc to just switch my Animator controller. But it spits out 999+ warnings saying the animator has not been initialized, like this:
Animator has not been initialized.
UnityEngine.Animator:SetBool(String, Boolean)
PlayerController:FixedUpdate() (at Assets/Scripts/Player/PlayerController.cs:277)

Then the animator goes from this:

to this:

So I’m not exactly sure what I’m doing wrong, but I’m sure it’s something simple. If I start the game and then manually change the Controller to what I want, it works 100% the way I want. No errors/warnings.

Any help is appreciated, thanks.

I think the path is relative to the Resources folder, and the asset must be inside a folder called Resources.

2 Likes

facepalm.jpg

I knew it would be simple. That did it, thank you.

If anybody else has this problem in the future I know how annoying it is to see someone with the same problem and not see a concrete solution. So my solution is:

I created a Resources folder in my Assets folder and placed my ArcherFemale folder in there(which has my animator controller/animations in it). Then changed the pathing to:

myAnim.runtimeAnimatorController = Resources.Load("ArcherFemale/Player_Archer_Female") as RuntimeAnimatorController;

And now it works.

1 Like