First: You don’t define the key handles ahead of time – they are returned by AddKey(). It’s “handle” as in “code pointer to thing” not “handle” as in “artist movable tangent.”
Second: The best way I’ve found is to read using the Keys member, and update using SetKeys()
FKeyHandle h1, h2;
h1 = TheCurve.AddKey(0.f, 0.f, true);
h2 = TheCurve.AddKey(1.f, 0.1f, true);
auto keys = TheCurve.Keys; // make a copy
keys[0].ArriveTangent = -1.0f;
keys[0].LeaveTangent = 1.0f;
keys[0].InterpMode = ERichCurveInterpMode::RCIM_Cubic;
keys[0].TangentMode = ERichCurveTangentMode::RCTM_Break;
TheCurve.SetKeys(keys); // update and broadcast to listeners
Thank you for yourt time. Unfortunately, this possibly works with FRichCurve, but not with the version that allows editing from the Editor (FRuntimeFloatCurve):
That’s not how the handles work. The handles are identifiers for the internal objects. A handle object that’s uninitialized doesn’t have any special powers. The fact that you have a variable in your program named h1 doesn’t matter – the value returned by AddKey() is the value you need to use to reference that particular key for that particular curve.
They’re essentially just integers.
The index makes no sense outside of the context of the curve itself. (The curve actually has a map from “index” value to actual-key-index, which is why it’s a “Handle” and not just a raw index.)
If you’re having “other issues,” then perhaps those are a clue to what’s actually not working as expected in your code?
Calling SetKeys() calls AutoSetTangents() which updates the tangents for keys with the TangentMode set to RCTM_Auto, so if you want to keep the specified values, set the mode to RCTM_Break. Like my code suggested.
The “other issues” are tangents not being used for all the keys when you define them as you suggest (= as return values only). I understand what you’re saying, but if you tried it yourself you would see that the tangents are not kept for all keys unless you declare them explicitly.
Thanks for your help, maybe this has to do with the fact that I’m using those curves from a custom animation BP node, which seems to have some special treatment by the compiler…?
I think the tangents are being overridden because you’re specifying RCTM_Auto and not RCTM_Break. That’s what RTCM_Auto does – it overrides the tangents you specify with “auto computed” values.