- Home /
How to access AnimationCurve at runtime
Unity introduced AnimationCurve as a runtime class. But there is no doc or any sample on accessing it while the game is running. I'll be greatful if someone can to me how to do. Thanks.
Answer by Statement · Mar 31, 2011 at 12:21 PM
You can't get AnimationCurves from an AnimationClip. Strangely/sadly you can only set or add curves.
You'll have to keep track of any curves you create procedurally, in a dictionary for instance.
Yes, now I saved the AnimationClipCurveData to disk and created a curve at runtime with it.
Answer by Statement · Mar 30, 2011 at 03:19 PM
What way do you intend to use it?
Here's an example usage for animating a light turn on through Evaluate. You edit the AnimationCurve in the inspector. You can also give it some simple default value through Linear and EaseInOut.
var intensity : AnimationCurve;
yield AnimateIntensity();
function AnimateIntensity() {
var duration = intensity[intensity.length - 1].time; var timer = 0.0f; while (timer < duration) { timer = Mathf.MoveTowards(timer, duration, Time.deltaTime); light.intensity = intensity.Evaluate(timer); yield; } }
I can process the curves in a editor script to meet my requirement. I just intend to know more about the class. It's a runtime class but can't be accessed at runtime, very strange.
I mean "Access" as obtaining it from a clip at runtime, not just assigning it in inspector as a static reference.
Answer by Varaughe · Oct 12, 2013 at 08:11 AM
If you want to edit at runtime an animation curve,check this out:
http://u3d.as/content/rus-artur-pfa/runtime-curve-editor (new version available ! )
Answer by $$anonymous$$ · Nov 15, 2016 at 10:51 AM
AnimationCurve curveX = AnimationUtility.GetEditorCurve(ac, "Bip01", typeof(Transform), "m_LocalPosition.x");
it's ok in editor mode.