Keyframe (AnimationCurve) won't update!

Hello, I have the following 2 values:

Vector3[] pos;
AnimationCurve curveY;

In the Start method I set 10 keys in the animation curve

Then in a for loop, I am trying to update update those keys with the new position

for(int i=0; i<complexity; i++){
    curveY.keys[i].value = pos[i].y;
    Debug.Log(curveY.keys[i].value +", "+ pos[i].y);
}

However, the debug shows the pos is constantly changing, but the curveY never changes! It always stays at the exact same value that was set in at the beginning.

I even tried this way but it doesn’t work either!

for(int i=0; i<complexity; i++){
    curveY.keys[i] = new Keyframe(curveY.keys[i].time, pos[i].y);
    Debug.Log(curveY.keys[i].value +", "+ pos[i].y);
}

Any ideas? :frowning:

Note that the array is “by value”, i.e. getting keys returns a copy of all keys and setting keys copies them into the curve.

You can’t just modify curve.keys[0] because that is not the key in the curve
get the whole array (copies by value), modify that, then set the whole array

Problem is there doesn’t seem to be a way to set the array aside from creating a new animation curve.

However I found a solution that works, which involves having my own array of keys, modifying that, and then using the curve’s built in function to adjust an existing key.

keysY[i].value = pos[i].y;
curveY.MoveKey(i, keysY[i]);

except for curve.keys = myKeys …?