Search Unity

  1. Check out the Unite LA keynote for updates on the Visual Effect Editor, the FPS Sample, ECS, Unity for Film and more! Watch it now!
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. Improved Prefab workflow (includes Nested Prefabs!), 2D isometric Tilemap and more! Get the 2018.3 Beta now.
    Dismiss Notice
  4. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice
  5. Want to see the most recent patch releases? Take a peek at the patch release page.
    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:
    99
    As far as I know, your only option is to extract the curve in the editor and serialize it separately.