Unexpected Animation Curve Functionality

I’m currently trying to implement quite a simple system where I can offset all the keyframes after a particular specified time by a set amount on any given animation on any object that has animations.

The part that I’m struggling with currently is that the functionality of AnimationCurve.RemoveKey(), AnimationCurve.AddKey() and AnimationCurve.MoveKey() don’t seem to do at all what they should do. Remove Key and Move Key flat out do not delete the specified Key. By using Move Key, it simply moves the key to the new location, but leaves another key where the old one was. Simply using remove key appears to do nothing. And whilst the new keys and their positions do appear on the animation curve when accessing it through the animation editor, the new keys added through Move Key or Add Key are not in the AnimationCurve.keys array.

Here is my current code (This assumes that curves is a list of AnimationCurves, and curveData is an array of AnimationClipCurveData. Selected Time is the time specified by the user to push all keyframes after back, and pushTime is the amount each keyframe after the specified time is to be push back by):

					for (int i = 0; i < curves.Count; i++)
					{
						AnimationCurve currentCurve = curves*;*
  •  				for (int j = 0; j < currentCurve.keys.Length; j++)*
    
  •  				{*
    
  •  					Keyframe currentKey = currentCurve.keys[j];*
    
  •  					if (currentKey.time > selectedTime)*
    
  •  					{									*
    
  •  						currentKey.time += pushTime;*
    
  •  						currentCurve.RemoveKey(j);*
    
  •  						if (j >= currentCurve.keys.Length)*
    
  •  						{*
    
  •  							currentCurve.AddKey(currentKey);*
    
  •  						}*
    
  •  						else*
    
  •  						{*
    
  •  							currentCurve.MoveKey(j, currentKey);*
    
  •  						}*
    
  •  					}*
    
  •  				}*
    

currentState.clip.SetCurve(curveData.path, curveData_.type, curveData*.propertyName, currentCurve);
}*

Any help would be appreciated._

I have established that in fact, the code was correct, but my issue is due to the fact that when animating transforms (position, rotation and scale) key frames are automatically synchronised together and that is causing keyframes to be left behind even after I have deleted them because they are in synch with other keyframes. I.e. when I delete or move a keyframe that adjusts an object’s X position, the new keyframe is created, and the old keyframe is deleted, but a new keyframe is put back where the old keyframe was to be in synch with the keyframe for the Y and Z positions.

Apparently AnimationUtility.GetEditorCurve() is used to counteract this issue, but I have no idea how exactly to utilise it, if anyone were willing to give a more in depth description than the script reference page, that would be incredibly useful.