Edit Keyframe of Animation Curve

I have an Animation Curve defined in the inspector for some float interpolation, and I’d like to then edit some of the Keyframe’s properties at runtime. However, something like

Curve1.keys[0].time = 5f;

seems to do nothing to affect the Keyframe. The best I can do is copy the Keyframe array, adjust it separately, and then reassign it back to the Curve. Am I missing something that would let me edit the variables as I need them?


The reason that does not work is because Keyframe is a struct, a value type. In UnityScript aka JavaScript they do work behind the scenes so it works. In C# you do it manually:

KeyFrame[] keys = Curve1.keys; // Know that this is making a copy of all keys
Keyframe keyFrame = keys[0];
keyFrame.time = 5f;
keys[0] = keyframe;
Curve1.keys = keys; // This is copying the keys back into the AnimationCurve's array.