Hello,
I’m trying to simply get the following code to work but I’m getting the error: “Animator.GotoState: State could not be found”
Animator animator = character.GetComponent<Animator>();
animator.Play("Base Layer.Run", 0, 0f);
And here is the setup:
The character I load dynamically does animate at the start with the default idle animation, but that’s just because of the Animator component.
Do I need to specify something else? I’ve tried what seems like all variations
And a related question: how does Unity know which AnimationController to pull the animation from? Shouldn’t I need to specify this? Like, what if two AnimationControllers have the same layer (i.e. Base Layer) and same state (like two Idle named the same)? Or is this system intelligent and will find the first matching state name (in which case why do we need to specify the layer)? I’m a little confused.
Thanks for any help.
That seems like it ought to automatically run anyway, as entry goes to Run
Also, I think you just use “Run” for the name.
AnimationControllers have animations slotted into the states.
1 Like
Thank you. I was using the method described in the documentation.
“When you specify a state name, or the string used to generate a hash, it should include the name of the parent layer. For example, if you have a Bounce state in the Base Layer, the name is Base Layer.Bounce.”
But I just had a thought: am I supposed to be doing this differently because I’m using the Basic Motions pack? Should I be changing the controller instead of trying to play an animation? Because this is what my setup looks like:

I feel like maybe I should be changing the Animator Controller out instead. I’ll see if I can find code to do this…
Though ideally I could do something like Play(“AnimationController/Run”)
That did indeed seem to be the issue. If anyone else comes across this problem, the following ended up working:
animator.runtimeAnimatorController = Resources.Load<RuntimeAnimatorController>("Kevin Iglesias/Basic Motions Pack/AnimationControllers/BasicMotions@Run");
animator.Play("Run", 0, 0f);
Thank you Kurt-Dekker and to anyone else taking a look.
1 Like