- Home /
Animation Runtime Controller - Change through code? C#
I want to have a store system in my game, and with the system I'm creating it requires a new animation controller on the player. For some reason I can't seem to make it work. Here is the code (C#):
if (PlayerPrefs.GetInt ("Current Player") == 0) {
anim.runtimeAnimatorController = Resources.Load ("Animations/Player.controller") as RuntimeAnimatorController;
}
if (PlayerPrefs.GetInt ("Current Player") == 1) {
anim.runtimeAnimatorController = Resources.Load ("Animations/GreenPlayerController.controller") as RuntimeAnimatorController;
}
I don't understand what is going wrong with this. I get no errors, but it does say that the Runtime Controller is empty so I know something is happening. Also I have checked to make sure the PlayerPref is working correctly and it is. I've searched everywhere but I can't find anything.
Thanks in advance!
Any extra information will be given when asked for.
Check the 'anim' variable: is it correctly handled for Animator?
Check if you are keep all your Animations folder like: 'Assets/Resources/Animations/.,,' .
Is it ok if the Animations folder is on it's own? like in the root Assets folder? Because I thought it just needed the path to the Animations folder, so it didn't matter if it was in the Resources folder.
when you use Resources.Load(...) statement, files must be in Assets/Resources folder. In your case - Assets/Resources/Animations/