USD: Python function "Import Asset tasks" adds Static Meshes as Actors and not as StaticMeshActors

Hi,

I have a python script with which I am importing a usd file. My problem is that StaticMeshes are not added as StaticMeshActors to my level. Instead as simple Actors. I need to have them as StaticMeshActors to perform tasks like MergeStaticMeshActors on them. That is working with the UI, but not with Python as the function expects StaticMeshActors and cannot handle simple Actors.

If it is available in 5.6, it would be also fine as we plan to switch. I would also be able to add a C++ function here via BPFunctionLibrary, if it is not possible with Python.

stageoptions = unreal.UsdStageOptions()
    
    import_options = unreal.UsdStageImportOptions()
    import_options.set_editor_property("bImportActors", True)
 
    import_options.set_editor_property("stage_options", stageoptions)
    import_options.set_editor_property("bimportMaterials", True)
    import_options.set_editor_property("bImportOnlyUsedMaterials", True)
    import_options.set_editor_property("bMergeIdenticalMaterialSlots", True) 
    import_options.set_editor_property("bImportGeometry", True)
 
    import_options.set_editor_property("bPrimPathFolderStructure", False)
    import_options.set_editor_property("override_stage_options", True)
 
    import_options.set_editor_property("kinds_to_collapse", 0)
    
    import_task = unreal.AssetImportTask()
    import_task.set_editor_property("automated", True)
    import_task.set_editor_property("destination_path", import_location)
    import_task.set_editor_property("filename", asset_path)
    import_task.set_editor_property("replace_existing", True)
    import_task.set_editor_property("save", True)
    import_task.set_editor_property("options", import_options)
 
    tasks = []
    tasks.append(import_task)
 
    unreal.AssetToolsHelpers.get_asset_tools().import_asset_tasks(tasks)

Thanks.

Hi Jan,

The developer in charge of USD is currently out of office. Back end of next week.

They will answer you when they are back.

Thanks for your patience.

Regards,

Jean-Luc

Thanks [mention removed]​ for letting me know,

something what probably also would work if I could replace the Actors with StaticMeshActors. So a simple in place conversion. Preferable with Python. So then I can use:

https://dev.epicgames.com/documentation/en\-us/unreal\-engine/python\-api/class/StaticMeshEditorSubsystem?application\_version\=5\.3\#unreal.StaticMeshEditorSubsystem.merge\_static\_mesh\_actors

Hi Jan,

Sorry for the delay.

The USD Importer uses generic actors except for the special case of the CineCameraActor and that hasn’t and will not change. You could try using convert_actors in the EditorActorSubsystem in Python to see if it fits your need to get StaticMeshActors from the generic Actors.

A new feature in the USD Importer that could be of interest to you is the introduction of a new CollapsingAPI schema in 5.5 to extend the functionality of the collapsing by kind. Instead of specifying the kind in your prim hierarchy and set the kind to collapse in the import options, you can now apply the CollapsingAPI schema on any prim and the importer will try to collapse the prim subtree into a single prim. So let’s say you have multiple mesh prims under an xform prim on which you apply the CollapsingAPI schema, the importer will merge the meshes into one mesh at import so you don’t need to do a MergeStaticMeshActors afterwards.

Another thing you could try is use Interchange USD to import your USD file. However, this is still experimental. To try it out in 5.6, enable the Interchange OpenUSD plugin in your project and enable its import into level functionality through the cvar Interchange.FeatureFlags.Import.USD.ToLevel 1. Then you can use File > Import Into Level… to import your USD into the level. It uses typed Actors and will generate StaticMeshActor where appropriate.

Finally, if you can implement your own C++ function, then you can take a look FMeshMergingTool::RunMerge in MeshMergingTool.cpp (this is what the UI calls) and compare with UStaticMeshEditorSubsystem::MergeStaticMeshActors in StaticMeshEditorSubsystem.cpp, which is the function that is exposed to scripting. You’ll notice that both utilize the same underlying function MergeComponentsToStaticMesh from the MeshMergeUtilities and there’s no inherent restriction to StaticMeshActor.

I hope that one of these options will work out for you.

Best regards,

Anousack

Thanks for the detailed answer. The convert_actors function seems to work for me.

Great! Thanks for reporting back.