# Python: Convert actors to static mesh

**URL:** <https://forums.unrealengine.com/t/python-convert-actors-to-static-mesh/152073>\
**Category:** Editor Scripting\
**Tags:** unreal-engine\
**Created:** [October 13, 2020, 7:06am UTC](https://forums.unrealengine.com/t/python-convert-actors-to-static-mesh/152073 "2020-10-13T07:06:56Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![KamilHep](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/kamilhep/32/1015845_2.png) [@KamilHep](https://forums.unrealengine.com/u/KamilHep)\
**Post date:** [October 13, 2020, 7:06am UTC](https://forums.unrealengine.com/t/python-convert-actors-to-static-mesh/152073/1 "2020-10-13T07:06:56Z")

</div>

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:

 ![unreal_convert_actors.PNG.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/3X/8/3/83699fe27311558932c896ec9e1e01e0470f701f.jpeg)

That’s how far I’ve got:

```auto

mso = unreal.EditorScriptingMergeStaticMeshActorsOptions(
   destroy_source_actors=False,
   new_actor_label='my_test',
   rename_components_from_source=True,
   spawn_merged_actor=False,
   base_package_name='/Game/TerrainTools/',
   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!

---

<div class="post-metadata">

**Author:** ![KamilHep](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/kamilhep/32/1015845_2.png) [@KamilHep](https://forums.unrealengine.com/u/KamilHep)\
**Post date:** [October 17, 2020, 7:27am UTC](https://forums.unrealengine.com/t/python-convert-actors-to-static-mesh/152073/2 "2020-10-17T07:27:30Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![grayback](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@grayback](https://forums.unrealengine.com/u/grayback)\
**Post date:** [April 11, 2021, 8:42pm UTC](https://forums.unrealengine.com/t/python-convert-actors-to-static-mesh/152073/3 "2021-04-11T20:42:06Z")

</div>

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)

---

<div class="post-metadata">

**Author:** ![UE\_FlavienP](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/ue_flavienp/32/1194546_2.png) [@UE\_FlavienP](https://forums.unrealengine.com/u/UE_FlavienP)\
**Post date:** [April 12, 2021, 3:03pm UTC](https://forums.unrealengine.com/t/python-convert-actors-to-static-mesh/152073/4 "2021-04-12T15:03:30Z")

</div>

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")
    quit()
 
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
unreal.Exporter.run_asset_export_task(task)

```

---

<div class="post-metadata">

**Author:** ![grayback](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@grayback](https://forums.unrealengine.com/u/grayback)\
**Post date:** [April 13, 2021, 5:10am UTC](https://forums.unrealengine.com/t/python-convert-actors-to-static-mesh/152073/5 "2021-04-13T05:10:52Z")

</div>

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  
 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/3X/0/c/0cf4cff93f6aeca98ca2ed58d2e062d1a602395b.png)

---

<div class="post-metadata">

**Author:** ![UE\_FlavienP](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/ue_flavienp/32/1194546_2.png) [@UE\_FlavienP](https://forums.unrealengine.com/u/UE_FlavienP)\
**Post date:** [April 13, 2021, 9:22am UTC](https://forums.unrealengine.com/t/python-convert-actors-to-static-mesh/152073/6 "2021-04-13T09:22:45Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![grayback](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@grayback](https://forums.unrealengine.com/u/grayback)\
**Post date:** [April 13, 2021, 2:12pm UTC](https://forums.unrealengine.com/t/python-convert-actors-to-static-mesh/152073/7 "2021-04-13T14:12:36Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![hosmiccooper](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/hosmiccooper/32/88714_2.png) [@hosmiccooper](https://forums.unrealengine.com/u/hosmiccooper)\
**Post date:** [November 15, 2021, 4:20am UTC](https://forums.unrealengine.com/t/python-convert-actors-to-static-mesh/152073/8 "2021-11-15T04:20:00Z")

</div>

Hello FlavienP.How can i export selected meshes one by one instead of merging all actors and exporting them ? Your script works but it merges all the actors and exports as a single mesh.Thanks in advance!

---

<div class="post-metadata">

**Author:** ![UE\_FlavienP](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/ue_flavienp/32/1194546_2.png) [@UE\_FlavienP](https://forums.unrealengine.com/u/UE_FlavienP)\
**Post date:** [November 15, 2021, 9:53am UTC](https://forums.unrealengine.com/t/python-convert-actors-to-static-mesh/152073/9 "2021-11-15T09:53:46Z")

</div>

Hello,

you can tweak the script:

- pass a static mesh in the “object” variable
- Do not use the “selected” option
- Use a different filename for each static mesh

```auto
output_path = 'D:/projects/FBX/'
actors = unreal.EditorLevelLibrary.get_selected_level_actors()
static_mesh_actors = unreal.EditorFilterLibrary.by_class(actors,unreal.StaticMeshActor)
for a in static_mesh_actors:
    task = unreal.AssetExportTask()
    sm = get_static_mesh(a)
    if sm == None:
        break
    task.object = sm
    task.filename = output_path+a.get_name()+'.fbx'
    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
    unreal.Exporter.run_asset_export_task(task)

```

---

<div class="post-metadata">

**Author:** ![hosmiccooper](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/hosmiccooper/32/88714_2.png) [@hosmiccooper](https://forums.unrealengine.com/u/hosmiccooper)\
**Post date:** [November 15, 2021, 8:06pm UTC](https://forums.unrealengine.com/t/python-convert-actors-to-static-mesh/152073/10 "2021-11-15T20:06:10Z")

</div>

Thank you!
