Knowledge Base: UE4 Sequencer Python Cookbook

Article written by Euan C.

UE4 Sequencer Python Cookbook

Sequencer is a cinematic editing tool that uses various specialized tracks which are used to define the makeup of scenes.
This document will be fo…


Hopefully, all of this will make it somewhere in the documentation. More examples and coverage of making/using unreal tools in your documentation and/or learning center would be very useful.

with Python, how does one add a Geometry Cache (alembic) section pointing to the proper alembic cache?

Found some answers.
Here is how to add a geom cache to a sequence:

cache_asset = unreal.load_asset("/Game/path/to/cache_asset")
cache_actor = unreal.EditorLevelLibrary.spawn_actor_from_object(cache_asset,unreal.Vector(x=0.0, y=0.0, z=0.0))

actor_binding = level_sequence.add_spawnable_from_instance(cache_actor)
# adding a geom cache
cache_track = actor_binding.add_track(unreal.MovieSceneGeometryCacheTrack)
anim_section = cache_track.add_section()
anim_section.set_range(start_frame,end_frame) # start and end frames

# add the cache asset 
params = anim_section.get_editor_property("params")

And this is of use to others who may be looking for it.
Adding sub sequences to another sequence:

 # this adds an empty subscenes track to add something too
master_track = top_sequence.add_master_track(unreal.MovieSceneSubTrack)
subseq = unreal.load_asset("/Game/path/to/subsequence" )
subsequence_section = master_track.add_section()
# shift to proper location in timeline

Excuse me, How to create a morph target sequence using python? I have imported a fbx with morph targets of face, and I could using ui to set a level sequence, how to implement it with python? Thank you
屏幕截图 2022-10-25 125746

Also,I have got another problem, when I first open the project(without opening the sequence), and using section.get_channels() to get the Face’s channels, it will return None, but if I once open the level sequence, it could work, I have tested the metahuman’s control rig sequence, the issue didn’t occur. So does anything else I need to set with morph target or the sequence? Maybe it’s a bug(I have meet it both in 4.26.2 and 5.0.3)

Did you find a solution?

I also found that I must open the sequence manually (after creating it) in the editor before any further manipulation was possible through python -
I have to call unreal.LevelSequenceEditorBlueprintLibrary.refresh_current_level_sequence() which also allows further python commands

How to get current shot subsequence range from master sequence?

anim_section.params.animation = anim_seq doesn’t reflect the level sequence. I am trying to import an AnimSequence.