How to batch export scene components to glb/glTF file

Hello,
What I want is to batch export my scene components or blueprint actor as glb/glTF file.

I found a free plugin (glTF Exporter) from Unreal Marketplace which is a great plugin that help me to export my scene component or blueprint actor as glTF/glb file.

But the problem is that if I have dozens of actor in my scene then I have to select one by one to export them and every time I export, the prompt appear on the screen. And this plugin and built-in fbx exporter merge all selected actor to one mesh which I definitely don’t want. I want them as separate file.

Then I found another solution to automate this process by executing python script.
In this case this python script allow me to batch export only asset from content browser.

Python Script: Export mesh as GLTF with Python - #2 by anonymous_user_a1bda113

So how do I batch export scene component or blueprint actor (not asset from content browser) as glb/glTF file.

Your help is much appreciated.
Thank you.

You can tweak a bit the script to:

  • make it iterate on actors in your scene
  • for each actor you will select them
  • then export to gltf but only the selected elements

In the following code notice that:

  • task.object is using the world
  • task.selected is true (if you do not it will export the full level)
  • task.options is a unreal.GLTFExportOptions()

You can iterate over actors and select them with something like that

for actor in unreal.EditorLevelLibrary.get_all_level_actors():
    selected_actors = [actor]
    unreal.EditorLevelLibrary.set_selected_level_actors(selected_actors)

and then you can export each selected actor or group of selected actors.

    task = unreal.AssetExportTask()
    # this could be just one asset if you only want to export one single asset
    task.object = selected_actors[0].get_world()
    task.filename = output_file
    task.selected = True
    task.prompt = False
    task.automated = True
    task.options = unreal.GLTFExportOptions()
    unreal.Exporter.run_asset_export_task(task)
1 Like

Thanks, . It works like a charm