Download

Importing assets into Unreal 4.20 using python

Hello,

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’

The API suggests that it should be passed an AutomatedAssetImportData (https://api.unrealengine.com/INT/PythonAPI/class/AssetTools.html) but this doesn’t work. Am I missing something or is this a bug?

Thanks in advance for your help.

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:

hope that helps.

Hello, thank you for your help. I have also tried that but it is also not working as expected, I have tried:

task = unreal.AssetImportTask()
task.filename = fbxFilePath
task.destination_path = ‘/Game/Meshes/Building/pythonTest1/’
task.automated = True
task.save = True
task.replace_existing = True
task.options = unreal.FbxSceneImportOptions()
task.options.set_editor_property(‘hierarchy_type’, unreal.FBXSceneOptionsCreateHierarchyType.FBXSOCHT_CREATE_BLUEPRINT)

tasks = [task, ]
unreal.AssetToolsHelpers.get_asset_tools().import_asset_tasks(tasks)
fbxScene = tasks[0].imported_object_paths[0]

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?

Thanks again.

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

you were right the issue was with the drive permission setting, now I have to edit the setting and after changing the access permission I am able to access my hard drive. To get the solution go here https://www.hptechsupportnumbers.com/blog/windows-detected-a-hard-disk-problem/

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.

I really enjoyed. :smiley: :smiley:

ufabet.org สมัคร ufabet หาเว็บแทงบอล คาสิโน : po

you can go to through this link for more information about it <ahref=“UnrealEnginePython/UnrealEnginePython.Build.cs at master · 20tab/UnrealEnginePython · GitHub”</a>
and also visit:<a href=“Download Adobe Photoshop CS6 Free for Windows PC - Full Version Zip File”></a>

Hi @Ro-Su-,

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.

Good Morning,

This is the way I’m importing assets from Fbx at the moment. But, it doesn’t use the ‘Import Into Level’ feature.
https://www.youtube.com/watch?v=SEjOZJ-IHro
Hope it still helps

I’m currently working to find how to make the ‘Import Into Level’ work.
I’ll let you know if I manage to do something useful with it.

Have a nice day,
Alex

Alex,
Thanks for the Video. Interesting stuff.

Let me know what you find out with the import into level. Looking forward to your update.

Cheers.

For now, I’m able to call the function with this code:



import unreal
data = unreal.AutomatedAssetImportData()
data.set_editor_property('destination_path', '/Game/MyNewFolder')
data.set_editor_property('filenames', 'C:/Assets/SM_ColorCalibrator.FBX'])
data.set_editor_property('level_to_load', '/Game/MyNewLevel')
data.set_editor_property('replace_existing', True)
factory = unreal.FbxSceneImportFactory()
data.set_editor_property('factory', factory)
unreal.AssetToolsHelpers.get_asset_tools().import_assets_automated(data)

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

After a little bit of research on UDN I found this: https://udn.unrealengine.com/questions/401847/view.html

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.

Doesnt sound too promising as dropping parts into a blueprint manually will make us lose the scene hierarchy as it was stored in the fbx to be loaded.

But thanks for digging into that, Alex.

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.

All my tests were in 4.21, but everything looks the same as 4.20 to me

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.

Have An Awesome And Productive Day

final grade calculator tutuapp flipkart customer care

Some How I have learned one of the best topics on python. I build a complete website using python.
The import is really great to have.
Thanks for the people who answered.