Adding a SkeletalMeshAnimation into a Sequencer with Python

Hello,

I’m trying to find a way to add an already imported animation into a sequence.
After multiple hours, I found a working solution in 4.22, but I think that it might not be the best way to do it.

Do you know any better way?
And
Is it possible to do it in 4.21?

Here is my starting point:




import unreal
# Get Actor from the world
actor = unreal.GameplayStatics.get_all_actors_of_class(unreal.EditorLevelLibrary.get_editor_world(), unreal.SkeletalMeshActor)[0]
# Get Sequencer
sequence_asset = unreal.LevelSequence.cast(unreal.load_asset('/Game/Sequences/SEQ_Test'))
# Add Actor in Sequencer
possessable = sequence_asset.add_possessable(actor)
# Get Animation
animation_asset = unreal.AnimSequence.cast(unreal.load_asset('/Game/Animations/AN_Test'))
params = unreal.MovieSceneSkeletalAnimationParams()
params.set_editor_property('Animation', animation_asset)
# Add track
animation_track = possessable.add_track(unreal.MovieSceneSkeletalAnimationTrack)
# Add section
animation_section = animation_track.add_section()
animation_section.set_editor_property('Params', params)
animation_section.set_range(0, animation_asset.get_editor_property('sequence_length'))



Alex, this is pretty much right. My code for setting the section range is:


animation_section.set_range(sequence_asset .make_range_seconds(0, animation_asset.get_play_length()))

And I set the range before setting the Params. Not sure if that matters…