UE5 Crash when adding keyframes to Animation Sequence after adding additional frames

TL;DR

Currently, on UE 5.0.0, the editor has a guaranteed crash when trying to create keyframes on a new animation sequence after adding additional frames. I’ve described a dirty fix below, but it may not be the correct solution.

Background

I did some digging in an attempt to find a workaround, but the only way I’ve found to fix this issue is to modify the UE5 source code and rebuild a custom version of the engine. Sorry to those of you hoping for a workaround in the release version of the engine, hopefully this will be fixed in 5.0.1!

From what I can gather, the bug seems to occur because the Animation Data Model is initialized with NumberOfKeys set to 2, but the arrays holding the Keyframes are only initialized with a single element.

The exception appears when adding the keyframe, in the UAnimSequence::BakeTrackCurvesToRawAnimationTracks method. First the ensure lines are all triggered on lines 4158, 4168, and 4181 of Engine\Source\Runtime\Engine\Private\Animation\AnimSequence.cpp but the editor will continue running. Then on line 4189, the line
FTransform LocalTransform(FQuat(RawTrack.RotKeys[KeyIndex]), FVector(RawTrack.PosKeys[KeyIndex]), FVector(RawTrack.ScaleKeys[KeyIndex])); throws an array access error when the forloop is on its last iteration.

The dirty fix I’m using at the moment to work around this problem is to add the following code to Engine\Source\Runtime\Engine\Private\Animation\AnimSequenceHelpers.cpp just after line 839 in the AnimationData::DuplicateKeys method

if (KeyData.Num() == 1) { // add extra keyframe if we're running into only 1 keyframe in the list, the minimum should be 2
	auto SourceKeyData = KeyData[0];
	KeyData.InsertZeroed(1, 1);
	KeyData[1] = SourceKeyData;
}

I’m not sure this is the best fix. I spent a few hours digging through all the animation code but was confused about where these bone animation tracks are being initialized. This fix just ensures that if we’re calling the DuplicateKeys method and the bone animation tracks only have a single element, we duplicate it so there are two elements and it matches the reported number of keyframes. I’m not sure how it interacts with the RemoveKeys method afterward, so it is probably worth someone with more knowledge of the UE5 codebase digging around further to fix this properly.

To reproduce this bug:

  1. Create a new project, I’m using the first person project as an example. It doesn’t matter if it’s a C++ or Blueprint based project, the bug occurs in both versions. I’m also including the starter content so I have a mesh to make animations for.

  1. Open the Content Browser, navigate to the Mannequin Arms Skeletal Mesh under Content/FirstPersonArms/Character/Mesh, right click it and choose edit

  1. In the menu bar, choose Create Asset → Create Animation → Current pose and save the animation in any location with any name

  1. Right click the top of the sequencer area and choose “Append at the end”, then enter any number of frames to add. I’m adding 2 in the example screenshots

  1. Now choose a bone from the Skeleton Tree panel, then click the “+ Key” button in the top menu bar

  1. The editor will crash due to an attempt to access an array beyond it’s length.

I hope this wasn’t overly long, but in my experience there’s no such thing as a bug report with too much detail! Looking forward to seeing what the correct fix ends up being for this.

Happy to provide additional information if necessary!

1 Like

Looks like the fix for this bug has been submitted and should applied be in the next release (5.0.1? 5.0.2?)

see commit ae39a8c35a547de7c04d621a93a8022b6c387139 on github

Thanks for the quick fix guys!

1 Like

This issue doesn’t seem to be resolved yet. I’m still having this issue and it’s really difficult trying to add new stuff to my game. I’m not well versed with Unreal Engine enough yet to be able to do the fix mentioned above, all my attempts have seemed to render Unreal Engine unusable.

I see 5.0.2 was just released and includes UE-150004 which was the fix for this bug report. Try updating to the latest and see if the issue persists. I won’t have time to check on the new version until later today.

This bug is still occurring and it’s upsetting. How do I submit a bug report?

You can report bugs here: https://issues.unrealengine.com/

I was able to confirm 5.0.2 fixed this specific issue.

If you’re still getting this crash on 5.0.2 feel free to post the traceback here and I can check if I see anything that might be an easy fix