Adding and editing Transform keyframes in sequencer from c++

I’ve found posts on how to set float keyframes, but nothing on how to set a transform keyframe (probably the most fundamental track type in a Level Sequence.)

Anyone have any sample code for adding and/or modifying keyframes on an existing Transform track and section in a Level Sequence?

Thanks in advance:)

OK, so this post gets me where I want to go, except…

It seems like it allows me to create keyframes (I can see them and if I query them by code they have the values I set), but when I play back the sequence it looks like it’s running off the previously compiled motion path. So I’m guessing I need to force the sequence to recompile with the new keyframes? Not sure how that works.

(For future readers, the post linked above exposes the individual transform channels, then use this post for info on how to add keyframes.)

For anyone looking at this: upgrading the project to 4.26 took care of the last hurdle. Prior to 4.26 you had to manually force a recaching of the timeline after adding keyframes. Now it happens automatically.

That’s great to know. Can you provide some sample code that work with key frame on unreal 4.26? Thanks in advance!

Sure. Here’s some basic code for adding a key to a specific section of a track:

FKeyStore is just my own struct storing the keyframe details. FMovieSceneFloatValue is UE4’s struct for storing keydata. “theKeyToAdd.Tangent” is the tangent information, which is another UE4 struct of type FMovieSceneTangent data. It stores the info for the bezier handles. The final AutoSetTangents command balances each added keyframe’s bezier weights to align with neighboring keyframes.

	FCriticalSection Mutex;
	ParallelFor(currentkeys.Num(), [&](int32 currentKeyIter)
		{
			FKeyStore *theCurrentKey = &currentkeys[currentKeyIter];
			FMovieSceneFloatChannel* theChannel = channelArray[theCurrentKey->keyChannel];
			FMovieSceneFloatValue theKeyToAdd;
			theKeyToAdd.Value = theCurrentKey->keyData;
			theKeyToAdd.Tangent = theCurrentKey->keyTangentData;
			theKeyToAdd.InterpMode = theCurrentKey->keyInterpMode;
			theKeyToAdd.TangentMode = theCurrentKey->keyTangentMode;
			Mutex.Lock();
			FKeyHandle theKeyHandle = theChannel->GetData().UpdateOrAddKey(theCurrentKey->keyTime, theKeyToAdd);
			deletionHandles[theCurrentKey->keyChannel].Add(theKeyHandle);
			Mutex.Unlock();
		});

	// Now we need to calculate auto tangents as needed
	ParallelFor(channelArray.Num(), [&](int32 channelIter)
		{
			channelArray[channelIter]->AutoSetTangents();
		});