Hi,
I am trying to create a linked animation sequence with python code so I can simply select a bunch of bindings and run a for loop over them that exports all selected sequencer bindings as linked animation sequences with one click rather than doing 1-by-1. This needs to be identical to the process of right clicking on a skeleton binding in Sequencer and saying “Create Linked Animation Sequence”.
Now, unfortunately their documentation on this is super limited with just unreal.SequencerTools.export_anim_sequence() and link_anim_sequence but I think these do the right things.
The issue is just creating the first animation sequence link. It doesn’t link the skeleton up or just crashes when doing it. I’m getting some of this code from my own and some from the example given.
import unreal
ll = unreal.LevelSequenceEditorBlueprintLibrary
ues = unreal.EditorLevelLibrary()
level_editor_subsystem = unreal.get_editor_subsystem(unreal.LevelEditorSubsystem)
world = ues.get_editor_world()
asset_tools = unreal.AssetToolsHelpers.get_asset_tools()
binding = ll.get_selected_bindings()[0]
def export_anim():
#s.export_anim_sequence()
anim_factory = unreal.AnimSequenceFactory()
binding = ll.get_selected_bindings()[0]
anim_seq_class = unreal.AnimSequence
try:
anim_sequence = asset_tools.create_asset("Anim_test", "/Game/", anim_seq_class, anim_factory)
except:
pass
anim_sequence = unreal.load_asset("/Game/Anim_test", anim_seq_class)
level_sequence = ll.get_focused_level_sequence()
export_option = unreal.AnimSeqExportOption()
export_option.export_transforms = True
# export_option.export_curves = True
export_option.record_in_world_space = 1
export_option.export_morph_targets = 1
export_option.evaluate_all_skeletal_mesh_components = 1
s.export_anim_sequence(world, level_sequence, anim_sequence, export_option, binding, create_link=1)
link = s.link_anim_sequence(level_sequence, anim_sequence, export_option, binding)
print(link)
return link
Does anyone have any hint on doing this properly? Thanks so much. I have been beating my head against the wall for days trying to get this to work. I’ve tried many different things and nothing is working. Later I’ll be automating the path given as a string but I’m trying this just as a base.
I got it working for the most part with some issues still remaining. But in case anyone else needs this:
import unreal
ll = unreal.LevelSequenceEditorBlueprintLibrary
ues = unreal.EditorLevelLibrary()
level_editor_subsystem = unreal.get_editor_subsystem(unreal.LevelEditorSubsystem)
world = level_editor_subsystem.get_current_level()
world = ues.get_editor_world()
eas = unreal.get_editor_subsystem(unreal.EditorActorSubsystem)
msbp = unreal.MovieSceneBindingProxy
mst = unreal.MovieSceneTrack
s = unreal.SequencerTools
from unreal import LevelEditorSubsystem
task = unreal.AssetExportTask()
ait = unreal.AssetImportTask()
ait.automated = 1
asset_tools = unreal.AssetToolsHelpers.get_asset_tools()
binding = ll.get_selected_bindings()[0]
eul = unreal.EditorUtilityLibrary()
d = eul.get_selected_asset_data()
les = unreal.get_editor_subsystem(LevelEditorSubsystem)
def print_names(object):
for i in object: print(i.get_display_name())
def export_anim(path="/Game/"):
path = path.replace("/All/", "/")
#s.export_anim_sequence()
level_sequence = ll.get_focused_level_sequence()
anim_factory = unreal.AnimSequenceFactory()
bindings = ll.get_selected_bindings()
for binding in bindings:
object_binding_id = level_sequence.get_binding_id(binding) #finally got the binding id
skmc = ll.get_bound_objects(object_binding_id)[0]
skm = skmc.skeletal_mesh
name = skm.get_name()
sk = skm.skeleton
anim_factory.preview_skeletal_mesh = skm
anim_factory.target_skeleton = sk
anim_factory.set_editor_property("asset_import_task", ait)
anim_factory.set_editor_property("edit_after_new", False)
anim_seq_class = unreal.AnimSequence
anim_sequence = asset_tools.create_asset(name, path, anim_seq_class, anim_factory)
# anim_sequence = unreal.load_asset("/Game/Anim_test", anim_seq_class)
export_option = unreal.AnimSeqExportOption()
export_option.export_transforms = True
export_option.record_in_world_space = True
export_option.export_morph_targets = True
export_option.evaluate_all_skeletal_mesh_components = True
export_option.export_attribute_curves = True
export_option.export_material_curves = True
export_option.export_transforms = True
export_option.transact_recording = True
s.export_anim_sequence(world, level_sequence, anim_sequence, export_option, binding, create_link=1)
Where the path I’m getting from the Blueprint from the Editor Utility Widget, just pasting it in and feeding it into the Evaluate Python Script function. Hope this helps someone. This was SO needlessly complicated. Make this easier Unreal, please. Still trying to figure out why some of the skeleton is erroring out when creating with script vs right clicking method. I get warnings. saying “LogScript: Warning: Accessed None trying to read property SkeletalMeshComponent”
Thank you for posting this. It really helped me. I was also trying to bake by the method that was in the documentation page but still I was getting errors like: “URigHeirarchy and Skeleton error”.
After reading your code I realized that we have to set the animation factory properties, i.e. specifying the skeletal mesh and the skeleton, before creating an empty animation sequence asset.
So glad this helped! I may put out youtube tutorials on the stuff I have found for unreal as python scripting in unreal is so complicated compared to other programs. Not many tutorials out there for this stuff I’m noticing. I’m not professional at all in it, but given the current resources out there something is better than nothing.
And yeah that’s exactly the error I ran into too until I realized how to extract and set the skeleton. Took me a while.