Tangents ignored while setting keyframes

I am setting an animation curve in the Inspector to exist between the range 0..1. Then on each instance of the prefab using that curve to create a new curve scaled to fit within positionMin & positionMax (values of which are randomised on instantiation).

So I create a new curve, scale the values and copy over the tangents and time. Unfortunately the tangents don't copy over as they are set in the Inspector, but always flat. Even if I set them to wild numbers in this loop (I've tried 0, -10 & 10) all I ever get back is flat tangents. Is this a bug, or am I doing something wrong? Any ideas on ways to do this that works?

(in javascript...)

var keyframes = new Keyframe[anim.length];
for( i=0; i<keyframes.Length; i++ )
    keyframes_.value = Mathf.Lerp(positionMin, positionMax, anim*.value);*_
 <em><em>keyframes_.time = anim*.time;*_</em></em>
 <em><em><em><em>keyframes_.inTangent = anim*.inTangent;*_</em></em></em></em>
 <em><em><em><em><em><em>keyframes_.outTangent = anim*.outTangent;*_</em></em></em></em></em></em>
<em><em><em><em><em><em>_*var newCurve = new AnimationCurve(keyframes);*_</em></em></em></em></em></em>

Ho big is your positionMin, positionMax? I think you need to scale tangents too. See my answer here how tangents are calculated:


If your value is big and tangent is small then it can look like flat tangets.

On the other hand it might be that tangentMode comes into play here...and I don't know how that works.