Python to call a C++ function that imports GLB files into the UEditor as UAsset resource files

[Image Removed]

[Image Removed]

In Unreal Engine, I’m using Python to call a C++ function that imports GLB files into the UEditor as UAsset resource files. However, this is an asynchronous task. How can I determine when all UAsset resource files have finished importing, so I can then notify my Python code to proceed to the next step?

重现步骤
Unreal Engine 5.5.4​

Python 3.10.11

Hi JQ Du,

This can actually be done entirely in Python if it is more convenient for you. For that, you should use the Interchange Manager API instead of the Asset Tools API. Here’s an example:

`def on_asset_imported (object):
unreal.log(“Finished”)

def import_asset (src_file_path, dst_content_path):

interchange_manager = unreal.InterchangeManager.get_interchange_manager_scripted()
source_data = unreal.InterchangeManager.create_source_data(src_file_path)

import_parameters = unreal.ImportAssetParameters()
import_parameters.is_automated = True
import_parameters.replace_existing = True
import_parameters.on_asset_done.bind_callable(on_asset_imported)

unreal.log(“Before”)

Blocking

#interchange_manager.import_asset(dst_content_path, source_data, import_parameters)

async
interchange_manager.scripted_import_asset_async(dst_content_path, source_data, import_parameters)

unreal.log(“After”)`In the example above, interchange_manager.import_asset() is blocking, while interchange_manager.scripted_import_asset_async() is asynchronous. The import parameters include a dynamic delegate “on_asset_done”, which can be bound to a Python callable making use of bind_callable(). Your Python function’s single parameter will receive the loaded asset object.

Alternatively, you can keep that C++ function, and use field UAssetImportTask.AsyncResults.OnDone to set a C++ callback to be executed when the import finishes. That C++ callback can then call a delegate passed into it, which your Python code can create and bind a callable to.

Please let me know if one of those solutions work for you, and feel free to ask if you need any further assistance.

Best regards,

Vitor

Thank you very much. Switching to a full Python implementation is a good idea.