# Adding and editing Transform keyframes in sequencer from c++

**URL:** <https://forums.unrealengine.com/t/adding-and-editing-transform-keyframes-in-sequencer-from-c/486653>\
**Category:** Cinematics & Media\
**Tags:** keyframes, unreal-engine, transform, question\
**Created:** [July 27, 2021, 3:42am UTC](https://forums.unrealengine.com/t/adding-and-editing-transform-keyframes-in-sequencer-from-c/486653 "2021-07-27T03:42:40Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pixerati](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Pixerati](https://forums.unrealengine.com/u/Pixerati)\
**Post date:** [July 27, 2021, 3:42am UTC](https://forums.unrealengine.com/t/adding-and-editing-transform-keyframes-in-sequencer-from-c/486653/1 "2021-07-27T03:42:40Z")

</div>

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:)

---

<div class="post-metadata">

**Author:** ![Pixerati](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Pixerati](https://forums.unrealengine.com/u/Pixerati)\
**Post date:** [July 27, 2021, 5:13pm UTC](https://forums.unrealengine.com/t/adding-and-editing-transform-keyframes-in-sequencer-from-c/486653/2 "2021-07-27T17:13:11Z")

</div>

OK, so [**this post**](https://answers.unrealengine.com/questions/813601/view.html) 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**](https://answers.unrealengine.com/questions/900679/how-to-add-keys-to-sequencer-track-using-c.html) for info on how to add keyframes.)

---

<div class="post-metadata">

**Author:** ![Pixerati](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Pixerati](https://forums.unrealengine.com/u/Pixerati)\
**Post date:** [August 5, 2021, 4:37pm UTC](https://forums.unrealengine.com/t/adding-and-editing-transform-keyframes-in-sequencer-from-c/486653/3 "2021-08-05T16:37:16Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![vickylzy](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/vickylzy/32/494509_2.png) [@vickylzy](https://forums.unrealengine.com/u/vickylzy)\
**Post date:** [September 2, 2021, 12:19pm UTC](https://forums.unrealengine.com/t/adding-and-editing-transform-keyframes-in-sequencer-from-c/486653/4 "2021-09-02T12:19:07Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Pixerati](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Pixerati](https://forums.unrealengine.com/u/Pixerati)\
**Post date:** [September 4, 2021, 10:13pm UTC](https://forums.unrealengine.com/t/adding-and-editing-transform-keyframes-in-sequencer-from-c/486653/5 "2021-09-04T22:13:00Z")

</div>

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();
		});
```
