Search Unity

How to access to a animation clip from the Animator component.

Discussion in 'Scripting' started by Jose_Gallardo, Mar 28, 2014.

  1. Jose_Gallardo

    Jose_Gallardo

    Joined:
    Jul 29, 2010
    Posts:
    42
    Hi,

    I have a "nice quest" to share with you :)

    I want to change an animation clip behaviour at runtime (Loop, Clamp, Once, PingPong). However, the gameObject only have the "Animator" component attached to it. The object have an animation made with the "Animation" window, so i have an Animator component linked to an Animation Controller and this to a Motion. However i am not able or I do not find the way to get the animation clip and change his behaviour.

    Any suggestion? help? :confused:

    Cheers
    Jose
     
  2. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    6,620
    Hi, I didn't test the following code, it's just was code-completion was proving me:
    Code (csharp):
    1.  
    2. GetComponent<Animator>().GetCurrentAnimationClipState(layerIndex)[index].clip.wrapMode = WrapMode.Clamp;
    3.  
    The new Animator takes away a lot of scripting functionality from the non-editor scripting API, which was available in the old animation system.

    We ended up writing custom editors for a few components that work with the animator and need to have information about things that can't be queried at runtime, such as reading state names.

    The custom editor just exists to extract information that is not available from the non-editor scripting API. We use editor functions, such as found in the UnityEditorInternal namespace (AnimatorController / StateMachine) and store this information in the component to have access to it at runtime.

    It's a lot more code than before to basically to the same thing and has to be split into two classes (component and custom editor). I'm not really happy with that workaround though.