Search Unity

StateMachine > to access to motion parameter?

Discussion in 'Animation' started by sama-van, Apr 8, 2015.

  1. sama-van

    sama-van

    Joined:
    Jun 2, 2009
    Posts:
    1,734
    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! :)
     

    Attached Files:

  2. sama-van

    sama-van

    Joined:
    Jun 2, 2009
    Posts:
    1,734
    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...
     
  3. Mecanim-Dev

    Mecanim-Dev

    Joined:
    Nov 26, 2012
    Posts:
    1,675
    What would you like to do exactly at runtime?
     
  4. sama-van

    sama-van

    Joined:
    Jun 2, 2009
    Posts:
    1,734
    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 :(...
     
  5. Mecanim-Dev

    Mecanim-Dev

    Joined:
    Nov 26, 2012
    Posts:
    1,675
    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.
    http://docs.unity3d.com/ScriptReference/AnimatorOverrideController.html

    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.