How to add keys in sequencer by python ?

Hey guys, how can I add keys on a track’s section in sequencer by python ?
I wanna add a transform animation on one actor, but I didn’t find any methods on section or track objects to achieve it.
Hope your suggestion, thanks.

I figured it out:
unreal.MovieSceneScriptingChannel and unreal.MovieSceneScriptingKey classes are used to handle the channels and keys on sections, e.g:



# add a key on a transform section's translate-x channel
tx_channel =  trans_section.get_channels()[0]
tx_channel.add_key(time=unreal.FrameNumber(10), new_value=50.0)

Hope this can help someone who runs into the same problem.

1 Like

Glad you figured it out. There’s also some examples in the source here::

Engine\Plugins\MovieScene\SequencerScripting\Content\Python

In particular, sequencer_key_examples.py

Hi, I’ve been looking into the sequencer_key_examples.py , but the only example concerning float keys puts everything in one array. Isn’t there a way to access one specific keyframe given its time? The example also goes thru all object bindings… isn’t it possible to deal only with an object that’s selected on Sequencer?

Where do I find good documentation about Sequencer and keyframes?

Thanks for your time.

Yeah, you hit the nail right on the head, Leo. The documentation and examples are sorely lacking on this in my opinion. Did you ever find any answers to your questions?

1 Like

Here’s a bit more info at least on Python and Sequencer
https://forums.unrealengine.com/docs?topic=265097

Thanks scott. yeah, I’ve read through that document and the other (few) pages I could find on the subject. Unfortunately they leave a lot out.

For instance: I’ve got a metahuman character in a level and he is being possessed by a level sequence. If I select him in the Outliner I can get the selected actor with:

unreal.EditorLevelLibrary.get_selected_level_actors()

But how do I get from this to, for instance, his ‘hips_ctrl’ in the sequencer?

I can iterate though ALL control rigs in the sequencer with this:

for RigProxy in unreal.ControlRigSequencerLibrary.get_control_rigs(level_sequence):
Rig = RigProxy.control_rig

…but I can’t find a way to find out which control rig is connected to which actor. Either the documentation is incomplete or there are a lot of missing basic commands.

Unfortuantely Unreal documentation drops off fairly quickly when you t4ry to dig much deeper.
I would assume there’d be a structure item to relate a rig back to the actor.
Just browsering a few web pages here in case you don’t see them.
https://docs.unrealengine.com/5.0/en-US/PythonAPI/class/ControlRig.html
https://docs.unrealengine.com/4.26/en-US/PythonAPI/class/ControlRigControlActor.html

https://docs.unrealengine.com/5.0/en-US/PythonAPI/class/ControlRigControlActor.html

https://docs.unrealengine.com/5.0/en-US/PythonAPI/class/ControlRigComponentMappedBone.html

Thanks for checking. Sadly I’ve looked at those pages and no luck. I’ve googled just about everything I can think of. Do you happen to know if anyone has posted finished unreal python tools that have to do with animation anywhere? It’d be helpful to see some. I looked but I’ve found none.

You could try the unreal slackers on Discord

I got this working with custom C++ functions. But I guess a way better way might be using this blueprint function library, UControlRigSequencerEditorLibrary | Unreal Engine Documentation. Not sure if you want to use a controlrig as well.

I haven’t, but I’ve stopped pursuing this. I’ll keep an eye out.

Hello,
don’t know if people are still looking into this, but you can get the actor bound to a rig by finding the top parent binding of the rig and use get_bound_objects.
For example:

rigs = unreal.ControlRigSequencerLibrary.get_control_rigs(level_sequence)
for rig in rigs:
    # this is the binding directly on top of the control rig (the skeletal component track for example)
    proxy_binding = rig.proxy
    # you can go up in the hierarchy to find the main binding
    parent_binding = proxy_binding.get_parent()
    # and this to get the actor bound to it
    bound_objects = unreal.SequencerTools().get_bound_objects(world, level_sequence, [parent_binding], level_sequence.get_playback_range())
    actor = None
    for bo in bound_objects:
        if len(bo.bound_objects):
            actor = bo.bound_objects[0]