kakyoism
(kakyoism)
April 17, 2019, 1:27am
1
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?
kakyoism
(kakyoism)
April 17, 2019, 2:00am
2
Found it myself.
Learned from this video:
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.
kakyoism
(kakyoism)
April 17, 2019, 3:00am
3
For the CLI solution, it should be
/path/to/UE4Editor-Cmd.exe /path/to/my.uproject -run=pythonscript -script="/path/to/my_script.py"