Edit Animation Curve Parameters With Code

I have an animation controller, and a clip. The clip has three curves (keyframes?) and they are all transform.position’s. I want to change the x/z value of all three curves with code, every time I call my method. Has anyone had experience with this, or have a solution?

I think I can explain this a little better.

  • I have an Animator component attached to a character.

  • I have a clip with three keyframes.

  • The three keyframes each contain a position.

  • I want to change the keyframes position with code whenever my method is called upon.

This thread suggests exposing the curve to the Inspector and assigning it to a clip manually - How to get a curve inside an AnimationClip - Unity Engine - Unity Discussions

In which case you can get the keys here - Unity - Scripting API: AnimationCurve.keys and set the corresponding values - Unity - Scripting API: Keyframe.value

Not ideal but it would work. I’m surprised AnimationClip doesn’t expose a get method for curves but that might be to protect the integrity of imported assets (or something - who knows).

Thanks, must have missed that when searching through threads. I’ll try it out, hopefully it works.