Search Unity

  1. Unity 2019.1 is now released.
    Dismiss Notice
  2. We've opened up a space to discuss, share feedback, and showcase everything related to the Unity Shader Graph! Come show us what you've made.
    Dismiss Notice

Get AnimationClip Values from Script

Discussion in 'Animation' started by soltex1, May 2, 2016.

  1. soltex1

    soltex1

    Joined:
    Apr 2, 2015
    Posts:
    14
    I have an AnimaitonClip (_myAnimation) with this values:



    How do I access them via script?

    Why this doesn't work?
    Code (CSharp):
    1.  
    2. var bind= AnimationUtility.GetAllCurves(_myAnimation);
    3. string propertyName = "localEulerAngles";
    4.  
    5.   foreach (var VARIABLE in bind)
    6.   {
    7.  
    8.   EditorCurveBinding xBind = EditorCurveBinding.FloatCurve(VARIABLE.path, typeof(Transform), propertyName + ".x");
    9.   EditorCurveBinding yBind = EditorCurveBinding.FloatCurve(VARIABLE.path, typeof(Transform), propertyName + ".y");
    10.   EditorCurveBinding zBind = EditorCurveBinding.FloatCurve(VARIABLE.path, typeof(Transform), propertyName + ".z");
    11.  
    12.   float x_value, y_value, z_value;
    13.  
    14.   AnimationUtility.GetFloatValue(this.gameObject, xBind, out x_value);
    15.   AnimationUtility.GetFloatValue(this.gameObject, yBind, out y_value);
    16.   AnimationUtility.GetFloatValue(this.gameObject, zBind, out z_value);
    17.  
    18.   }
    x_value, y_value, z_value should be my values because GetFloatValues "Retrieves the current float value by sampling a curve value on a specific game object.", however the values are from the current model rotation instead...

    It's because I can't get the curves in runtime? (http://answers.unity3d.com/questions/33388/accessing-keyframes-from-an-animation.html)
    What are my alternatives to achieve this? Any ideias?
     

    Attached Files:

  2. derfeind2k

    derfeind2k

    Joined:
    Sep 12, 2018
    Posts:
    2
    I have the same problem in 2018 :(

    Still no solution for this ?
     
  3. SilentSin

    SilentSin

    Joined:
    Jan 3, 2013
    Posts:
    263
    As far as I know, your only option is to extract the curve in the editor and serialize it separately.