Download

Python scripting for importing custom assets.

The posts I found on importing with Python seem to all use the stock asset factories that UE Python API offers. I’ve seen:

https://forums.unrealengine.com/deve…0-using-python

https://forums.unrealengine.com/unre…es-with-python

I wonder how to import a custom asset based on a custom binary/text file, given that the asset factory has been defined in a plugin,
and it works to import the asset into the Editor by hand. Do I have to rebuild the Editor from source to have the factory available to Python?

Found it myself.

Learned from this video:
https://youtube.com/watch?v=M9UlyVtD5Dk



import unreal as ue

file = '/path/to/asset.my'

# Create an importing task

task = ue.AssetImportTask()
task.set_editor_property('automated', True)
task.set_editor_property('destination_name', '')
task.set_editor_property('destination_path', '/Game/My/Destination/Folder')
task.set_editor_property('filename', file)
task.set_editor_property('replace_existing', True)
task.set_editor_property('save', True)


# Run the task

ue.AssetToolsHelpers.get_asset_tools().import_asset_tasks([task])


Given that I already have a plugin that defined the factory for *.my. This code should work when executed in the Editor.

For the CLI solution, it should be



 /path/to/UE4Editor-Cmd.exe /path/to/my.uproject -run=pythonscript -script="/path/to/my_script.py"