Replace clip in Animator at runtime by State Name

Hello,

I am trying to replace a clip of a given state at runtime. I know the name of the State, and I’m currently in it, but I can’t find any way to get my AnimationState. All I can get are AnimatorStateInfo, but they won’t let me access the clip.

I have tried a lot of solutions like those described here:

However, those doesn’t work for me because they use the clip’s name rather than the state name. (I may have several states using the same clip, and I don’t necessarily know the name of the clip I want to replace although I know the name of the state).

I also don’t want to create one state per animation I need to play (I’m gonna pick the animation in a bank of 100s of clips, so creating all the states and transitions).

Has anyone got a solution for that problem? @Mecanim-Dev maybe?

Thanks!

I ended up doing this :

AnimationPlayableUtilities.PlayClip(characterAnimator, clip, out cinematicGraph);

It does the job.

1 Like