Altering animation curves via script

Hi,
I’m trying to write an editor extension that alters an animation curve via script. Unfortunately, any attempt I make to silently alter the value of the animation clip fails silently.

I first tried using curve.AddKey but this fails to change the value but that failed to change it (no error, just no change), so I tried altering the keyframe directly.
Stepping over the line ’ curve.keys_.value = value;', I can see in the debug watch that ‘curve.keys*.value’ never changes - it’s as if the ‘set’ property method is implemented but does nothing._
void FindOrAddKey(AnimationCurve curve, float time, float value)
_
{_
for (int i = 0; i < curve.keys.Length; ++i)
_
{_
_if (curve.keys.time == time)
{_
_curve.keys.value = value;
return;
}
}
curve.AddKey(time, value);
}*

My question is if this is intentional or if it’s a bug in Unity? Also, is there another way to edit the curve (I can’t find a way to remove a curve from an animation either - there’s no opposite of ‘AnimationUtility.SetEditorCurve’ as far as I can see.
Thanks for your time._

For anyone else looking, there is a simpler method of modifying key values without having to remove/add.

Keyframe[] keyframes = animationCurve.keys;

keyframes[0].value = 0;
keyframes[1].value = 1;
keyframes[2].value = 0;

animationCurve.keys = keyframes;

got it - you have to remove the key and re-add, like this:
static void FindOrAddKey(AnimationCurve curve, float time, float value)
{
for (int i = 0; i < curve.keys.Length; ++i)
{
if (curve.keys*.time == time)*
{
curve.RemoveKey(i);
break;
}
}
int key = curve.AddKey(time, value);
}