Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

How to get a curve inside an AnimationClip

Discussion in 'Scripting' started by ratamorph, Aug 24, 2009.

  1. ratamorph

    ratamorph

    Joined:
    Sep 2, 2007
    Posts:
    458
    I need a way to get a curve stored in an AnimationClip so I can sample the curve and create a path using a line renderer that shows the object's path but is also able to jump to any time and show the path at that time.

    I looked at the docs and only see SetCurve, is there a GetCurve anywhere? how can I do this at runtime?
     
  2. cyb3rmaniak

    cyb3rmaniak

    Joined:
    Dec 10, 2007
    Posts:
    162
    Check this out... I don't know exactly if this is what you need, but it's the closest thing I ever saw to what you need. AnimationUtility.

    But I doubt an animation clip received from a 3d app even has some kind of curve animation in it from the get go...

    From what I know AnimationCurves were introduce to give users a way to create NEW animation curves, both using scripts and nifty editor graph windows and assign them to properties. This allows animation editing inside the unity editor in a graphic way, instead of receiving just keyframes from 3d apps.

    So I have no idea what you can acomplish with that editor class, but I guess you can have a whack at it...
     
    Laiken and samana1407 like this.
  3. ratamorph

    ratamorph

    Joined:
    Sep 2, 2007
    Posts:
    458
    I looked into AnimationUtility, the problem is that my script needs to get the curve at runtime and if I'm correct Editor classes only run in edit mode.

    I'm also planing on animating the object using the timeline from Unity 2.1 so those clips should have curves on them, the problem is how to access them.
     
    TobyWu likes this.
  4. cyb3rmaniak

    cyb3rmaniak

    Joined:
    Dec 10, 2007
    Posts:
    162
    If that's the problem, you can try exposing a variable in one of your scripts as a type of AnimationCurve.
    Then use the EditorScript to extract the desired curve and set the variable to it. It will be serialized and saved with the scene.
    Or, in case it can't be serialized in the inspector, you can maybe create a class to copy the values, and later use those values to create a new AnimationCurve in runtime...
    Or better yet - serialize it yourself if necessary and in runtime de-serialize it back.

    I'm still not convinced this is a good approach, but I'm really interested to see what you can come up with...

    BTW- Do you keep changing the animation or something like this? Because if not - all these curves can be easily exported from the 3d app as a text file you can parse.
     
    Laiken, liangzhenjie and Malbers like this.
  5. ratamorph

    ratamorph

    Joined:
    Sep 2, 2007
    Posts:
    458
    That's actually a pretty nice workaround, didn't think of using the AnimationUtility to extract the curve in edit mode so I can use it runtime, I'll give that a shot.

    Thanks a lot!
     
  6. liangzhenjie

    liangzhenjie

    Joined:
    Aug 19, 2017
    Posts:
    1
    Thank you for the workaround! Although long time has passed!
     
  7. XsongyangX

    XsongyangX

    Joined:
    May 25, 2019
    Posts:
    18
    Hopefully there will be a way of extracting that information at run-time. :)
     
    Ajasmm02 likes this.
  8. Ray_Sovranti

    Ray_Sovranti

    Joined:
    Oct 28, 2020
    Posts:
    172
    Not likely. In runtime, Animations are basically a black box. If they haven't changed that by now I don't see any reason they ever will.
     
  9. yzzxz

    yzzxz

    Joined:
    Dec 23, 2019
    Posts:
    1
    12 years ago ,now i also hope to get that information at run_time
     
  10. Eristen

    Eristen

    Joined:
    Jun 17, 2021
    Posts:
    17
    Frakcture likes this.