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)