Section::TrimSection resulting in bad key values at start and end of trim range

The trim process inserts keys at the start or end of the range depending if you specify Trim Left or Right, I’m finding that Trim right is inserting a key at the end of the section that is incorrect.

Ie. my initial Section contains 2 keys, T=-70,V=0 and T=1314,V=1901

If I TrimLeft at Time 1173 I get a key inserted at T=1173 with a value of 1689.5, which is correct.

If I then TrimRight at Time 1226 I get a value inserted at 1226 with a value of 1738.03, this is wrong, value should be 1769.

Also All keys added by the trim command are set to Cubic(Auto) with there in out tangents being 0 (horizontal), so the resulting curve follows an S shape rather than the Linear path the original source curve follows.

Any help on how to fix the key value and tangent errors is most appreciated.

[Attachment Removed]

Steps to Reproduce
Create a transform Animation track in sequencer and in my Case Key the yaw value with Frame -70, value 0 and Frame 1314, value 1901, ensure curve is set as Linear interpolation.

Write code to use get the transform track and its single section, Duplicate Section then use TrimSection to trim keys outside set ranges, set Section range to new trimmed range, add section to track and delete the original section.

Simple code snippet I’m ussing to create a duplicate of the original Section containing 2 keys and then trimming it to a new range:-

UMovieSceneSection* NewSection = DuplicateObject<UMovieSceneSection>(Section, AnimTrack);

FQualifiedFrameTime PrevQFT(PrevScaledFrame, DestRate);

FQualifiedFrameTime QFT(TrimEnd, DestRate);

NewSection->TrimSection(PrevQFT, true, true); // delete all keys to left of new section start

NewSection->TrimSection(QFT, false, true); // delete all keys to right of new section end

TRange<FFrameNumber> CamRange = TRange<FFrameNumber>(PrevScaledFrame, TrimEnd);

NewSection->SetRange(CamRange);

[Attachment Removed]

Further investigation would suggest the TrimRight key value is incorrect because the TrimLeft operation inserted a key with Cubic interpolation and its tangent values being incorrect (0).

Does TMovieSceneCurveChannelImpl<ChannelType>::DeleteKeysFrom need to call AutoSetTangents(); or similar on the cubic key that has just been added?

[Attachment Removed]

Hey there,

This is a bug, thanks for raising it. I’ve logged an issue that you can follow here if you like: https://issues.unrealengine.com/issue/UE-358458, it’ll take a bit to show up. We think you’re on the right track with setting the auto tangent, but it’s a bit of a lower priority bug for the moment to fully verify..

As a workaround you could try looking at the keys before and after where the new key is added, and try to match the interp mode and tangents.

Dustin

[Attachment Removed]

Thanks Dustin, I was going to do the key thing as a last resort :slight_smile: But will try that now.

I did try calling AutoSetTangents() in TMovieSceneCurveChannelImpl<ChannelType>::DeleteKeysFrom dirrectly after AddCubicKey was called but that didn’t seem to work/help :(, I thought it may set the in out tangents on the new key to follow along the linear path of the 2 original keys, but didn’t seem to do so.

[Attachment Removed]

Hi,

I’ve submitted a fix for this in UE5 Main as CL 49681090. The issue with the tangents came from calling AutoSetTangents after deleting keys, so even if they were correct when adding they keys, they would be overwritten after the fact.

I also updated DeleteKeysFrom to use the interpolation from the curve instead of just assuming cubic.

Thanks!

[Attachment Removed]