I’ve been trying to use the new interchange module to import some meshes with a python script, and I would like to be able to run the script in a commandlet, but it crashes evertime.
Here’s the code
I’m running it with UnrealEditor-Cmd.exe C:\Path\to\project.uproject -run=pythonscript -script="importscript.py"
But I get a lot of errors and stack traces, starting with:
After a little bit of trying to debug it and also reading the implementation code, it looks like the interchange module starts in an async task the import process, but the import_asset function returns early, and the editor-cmd tries to shut everything down even though the import task is not yet completed.
I’ve tried to use time.sleep, as well as an asyncio event loop, but it looks like the task is on the same thread, and get blocked by the python execution, but as soon as the python execution is over, it will shutdown everything.
Hello,
so I checked with dev and it is a bug. The importasset and importscene should not be async, there are other functions for that.
What I can propose you for now is to run an import task instead. Import task will use the default pipeline for a file format. For glTF it should be interchange and will do similar to importasst:
That makes a lot of sense not to be supposed to work asynchronously, since the function return value is documented as true if the import succeed, false otherwise.. And that will also make its use in the editor much simpler (rather than having to always track which mesh has been already imported during the import callbacks).
I used to have this workflow with the AssetImportTask on 5.0, but the GLTF import options (unreal.GLTFImportOptions — Unreal Python 5.0 (Experimental) documentation) are really limited, and the primary reason for switching to the interchange system was to be able to use options such as merging meshes on import, or having mesh defaults, like enabling nanite. (And this is also why I am so happy about all the work that went into the Interchange subsystem).
Is the issue already tracked internally, or should I send myself a bug report ?
Somehow this doesn’t completely work for me.
It looks like the importer actually doesn’t really care about the default pipeline settings. I tried modifying the nanite setting and running the commandlet, but it doesn’t actually follow the settings I’ve set. (Both with replacing the default pipeline with a custom one, or changing the default one).
What works though, is changing the default pipeline, manually import a mesh in the editor, and in the pipeline configuration window, click the “reset to Default”.
Only then, when running the commandlet will it follow the pipeline configuration that I’ve set.
It looks like there’s a cached intermediate configuration somewhere, that I need to “reset to the Default” everytime I change the default pipeline configuration.