I am trying to use the Python interface to load in a .fbx file in an automated manner, essentially trying to replace the ‘File → Import into Level → …’ process. Currently I am trying:
importInfo = unreal.AutomatedAssetImportData()
importInfo.destination_path = ‘/Game/Meshes/Building/pythonTest1/’
importInfo.factory = unreal.FbxSceneImportFactory()
importInfo.filenames = [fbxFilePath, ] # This is the file path to the .fbx file
importInfo.level_to_load = ‘temp’
importInfo.group_name = ‘tmp’
fbxScene = unreal.AssetTools.import_assets_automated(importInfo)
But this throws the error:
TypeError: descriptor ‘import_assets_automated’ requires a ‘AssetTools’ object but received a ‘AutomatedAssetImportData’
Hey, that is odd. As you say, the signature for that function says it wants an AutomatedAssetImportData, but the code is expecting something else.
Fortunately, you can do the same automated import another way. You create an unreal.AssetImportTask(), set it up with the parameters you need, including automated = True, then pass the task inside an array in a call to unreal.AssetToolsHelpers.get_asset_tools().import_asset_tasks(tasks).
For a code example, you can see how our Shotgun integration does it here:
This runs however it seems to ignore setting the task.options to FbxSceneImportOptions. If I run it with task.automated=False, it brings up the Fbx Import Options dialog box rather than Fbx Scene Import Options and the hierarchy option is not on the Fbx Import Options box.
If I have understood this correctly, using task.options = unreal.FbxSceneImportOptions() should be the equivalent of taking me through the File → Import into Level → … process, am I missing something here?
Basic ability to select face/s and perform operations on them, such as detaching to create a new mesh, deleting, or flipping their normals. This helps fix import problems where changing the source data is difficult or impossible. Mobdro
I can confirm that using task.options = unreal.FbxSceneImportOptions() does not work as expected. It seems to do a standard static mesh import. This would be great to have working in Python.
Do you have any more input on how to rebuild the ‘import into level’ functionality in python without an UI popping up? I can also confirm that task.options = unreal.FbxSceneImportOptions() does not do what you would expect as it just does a static mesh import without building a blueprint and retaining the scene hierarchy.
Maybe we are just using it wrong?
There seems to be no proper example out there and the documentation doesnt help, really to understand how that feature is supposed to be used. I am not an engine programmer, so it is pretty hard to get a grip on that topic.
Some more help and direction would be much appreciated. Thank you.
But I’m not able to prevent Unreal from showing the pop-up asking for the import settings.
It does not seem to have a way to avoid GetFbxSceneImportOptions() from UFbxSceneImportFactory
That’s some progress right there. I tested and can confirm your findings. Unfortunately, when I run the code again, the replace_existing flag doesnt seem to have an effect resulting in duplicated static meshes as well the blue print class.
If it helps I gave up on this specific problem and just accepted that I had to click through some menus. I also had the same problem with a some other processes I am trying to automate, such as importing JSON files and assigning them for use, there are some menus that at present don’t seem possible to automate. I haven’t tried 4.21 yet but looking through the release notes I could not see anything Python specific but was just wondering if anyone has tried this stuff in that? I am hoping that at some point Epic will fix all these bugs as using Python is potentially a great feature but at the moment I find it is just too inconsistent to regularly use for automation.
I thought I would give an update…I managed to suppress the import dialog when importing into scene by modifying the FbxSceneImportFactory.cpp by basically not showing the window and adding the import options in the same cpp (for now).
My changes are currently hard coded (setting import parameters in code instead of an external JSON) and not fancy at all, but it does the job for me, at the moment, having an automatic import without user interaction.
has anyone else found that when importing an animation with this method, even if “import_mesh” is set to False, the mesh is still imported (if there was a mesh in the FBX of course)? I’m seeing this consistently.
I’m having the same (or a very similar) issue where every time I import animation it brings with it a skeletal mesh. I have set both “import_mesh” and “import_as_skeletal” to False in the import options, but it still happens. For the time being I’ve got around it by writing some extra code that deletes the new skeletal mesh after import. It’s not ideal but it’s the best I’ve been able to come up with so far.
Also, my code specifies I want to apply my imported animation to a particular skeletal mesh in my project. Yet on import the animation is instead connected to the new skeletal mesh that gets brought in with the animation. But as soon as the imported skeletal mesh gets deleted (with code or manually) the animation then connects to the “correct” skeletal mesh.