StateMachine > to access to motion parameter?

Hi,

Is there any way to access to the Motion parameter from the StateMachine?
Let say the layer name is “MainCharacter” and the state name “Idle”.

To be sure there is no confusion, I added a scree below with the thing I am talking about…

Thanks! :slight_smile:

2058770--134037--Capture.PNG

The editor method is the following :

UnityEditor.Animations.AnimatorControllerLayer [ ] al = animator.GetLayerIndex (“MainCharacter”); UnityEditor.Animations.AnimatorState sm = al[idleState].stateMachine.defaultState;
sm.motion = clipIdle;

but nothing for realtime use? O_o…

What would you like to do exactly at runtime?

Well I would like to re-use the graph I made for another character.
Behavior is 100% the same but animations would be different.
Then looking for a way to edit every Motion input with an animation clip by the clip from another character.

Everything is ready… just need this script to access to the Motion variable on each AnimationState :(…

You cannot access AnimatorState at runtime, this is an editor class only.

What you are looking for is called AnimatorOverrideController. This object allow you to override clip from a controller at runtime.

So I would suggest you to create a complete AnimatorController first and then you can create override for all your other character.

There is a little down side however, and AnimatorOverrideController can only override animation clip, so if you have some AnimatorState without any animation clip you won’t be able to define a clip in your override controller.