Animation clip keyframes to AnimationCurve

Hello!
I am trying to make an editor script where you can attach an animation clip and the script loops through all of its keyframes in the posX and adds them to a new AnimationCurve[ ] variable

How can i acces the animation clip data?

It doesn’t appear like the AnimationClip API gives you this ability at runtime.

Perhaps you could get at it in the editor with a custom asset importer for animations?

If you absolutely need the data at runtime, you could “run” the animation through its time interval at whatever spacing you want and call .Sample() to apply animated data, then read those values out of the target animated object, essentially “baking” the animation like the alembic animation format does:

Sorry i forgot to mention that i don’t want to do this in runtime. I want to get the position.x curve from a specified animation and load the data into a AnimationCurve, so i can use the AnimationCurve to simulate root motion… Maybe AnimationUtility can do this?