Bake animation curves with control rig

I was finally able to bake the animation using the LevelSequence way, I had to set the animation track section option “force_custom_mode” to True. For some reason the ControlRig is then correctly evaluated and the animation can be baked correctly.

Here is the complete process for anyone wanting to bake animation curves using a ControlRig and Python:


# Create a LevelSequence
# Spawn a SkeletalMeshActor in the current level.

# Create a binding using a SkeletalMeshActor from the current level.
bindingProxy : unreal.MovieSceneBindingProxy = levelSequence.add_possessable(skeletalMeshActor)

# Create an animation track to play your animation.
animationTrack : unreal.MovieSceneSkeletalAnimationTrack | None = bindingProxy.add_track(unreal.MovieSceneSkeletalAnimationTrack.static_class())
animationSection : unreal.MovieSceneSection = animationTrack.add_section()

# Set the number of frames.
nbFrames : int = animSequence.get_editor_property('number_of_sampled_frames')
animationSection.set_range(0, nbFrames)

# Set your animation
animationSection.params.animation = animSequence

# The option to make it works
animationSection.params.force_custom_mode = True

# ...
# Then add your ControlRig to your track using unreal.ControlRigSequencerLibrary.bake_to_control_rig(...).
# Reactivate your animation track using animationSection.set_is_active(True).
# Then use unreal.SequencerTools.export_anim_sequence(...) to bake and export your new animation.
# Done.