Python: Convert actors to static mesh

What’s the best way to convert selected actors to static mesh in python?

I basically want to replicate (or call if it’s possible) this command on the selected actor:

That’s how far I’ve got:

mso = unreal.EditorScriptingMergeStaticMeshActorsOptions(
   mesh_merging_settings=[256, [[1024, 1024], 4.0, 0.0, 0.5, 0.0, 0.5, 1.0, 1.0, 1.0, unreal.TextureSizingType.TEXTURE_SIZING_TYPE_USE_SINGLE_TEXTURE_SIZE, unreal.BlendMode.BLEND_OPAQUE, True, True, False, False, False, False, False, False, False, False, False, [1024, 1024], [1024, 1024], [1024, 1024], [1024, 1024], [1024, 1024], [1024, 1024], [1024, 1024], [1024, 1024], [1024, 1024], [1024, 1024], [1024, 1024]], 0, unreal.MeshLODSelectionType.CALCULATE_LOD, True, False, False, False, False, False, False, True, False, False, True])

x = unreal.EditorLevelLibrary.get_selected_level_actors()[0]
comps = x.get_components_by_class(unreal.StaticMeshComponent.static_class())
unreal.EditorLevelLibrary.merge_static_mesh_actors(comps, mso)

But unforunately getting this error:
LogEditorScripting: Error: MergeStaticMeshActors failed.

**I appreciate any help, guidance or direction. **

Thank you!

Looks like that code is in MeshUtilities.cpp for some reason **MeshUtilities **aren’t exposed throught python ??

I wish to be wrong but seems like it’s imposible to convert selected actors to static meshse easily in Python. Only one solutuon is to go and the rewrite code from MeshUtilities.cpp to python, sounds like lots of work. Just wanted to clarify with someone who knows Unreal Source code and Python if that’s the only way?

Many Thanks!

Hi! Did you ever find out how to achieve this? I need to convert some BP stuff into static meshes to merge and export to FBX. (Or some other way to do this could be good too)

The python function expects an array of static mesh actors. You cannot pass components or an instance of classes that are not subclasses of static mesh actors.
You could reparent your BP to static mesh actor so you can then perform a merge on it.

To export selected actors to FBX you can run something like that

output_file = 'C:\\Temp\\ue4_output.fbx'
selected_actors = unreal.EditorLevelLibrary.get_selected_level_actors()
if len(selected_actors) == 0:
    print("No actor selected, nothing to export")
task = unreal.AssetExportTask()
task.object = selected_actors[0].get_world()
task.filename = output_file
task.selected = True
task.replace_identical = False
task.prompt = False
task.automated = True
task.options = unreal.FbxExportOption()
task.options.vertex_color = False
task.options.collision = False
task.options.level_of_detail = False

That actually works even with blueprint actors with skeletal meshes! I was able to export a couple of different actors, but now the issue is that alot of the materials didn’t follow through

The FBX exporter is not really a fully fledged feature as usually UE is used as the end application.

There is a glTF Exporter that is coming soon on the marketplace and some work done on USD import/export too in upcoming versions. Maybe those would be better alternative to export your scene?

Awesome, I will definitely check that out! Thank you so much for taking the time ( BTW, that export script is already coming in handy :ok_hand: )