Can I import a png/jpg file to a material using python? Or import it as a texture (which I've done) and turn that in to a material using python

Hi,
I’m trying to automate the import of multiple png files to create materials that can be applied to meshes. When I import, the material created is completely black instead of the image I tried to load. I’ve also tried importing to texture (which creates a new texture completely fine) and then turn the texture to a material but still no avail.

I’ve tried the create_asset function and import tools to try and create this new material but can’t seem to crack it. Any help would be appreciated. Code I’ve tried is posted below:

##create_asset attempt

##create_asset attempt:

path = '/Game/Textures'
file = 'new_image2.png'
factory = unreal.MaterialFactoryNew()
asset_tools = unreal.AssetToolsHelpers.get_asset_tools()
asset_name = 'new_image2_mat'

new_material = asset_tools.create_asset(asset_name, path, None, factory)

##import attempt

from os import listdir
import_tasks = []
AssetTools = unreal.AssetToolsHelpers.get_asset_tools()
file = 'C:\\new_image2.png'
AssetImportTask = unreal.AssetImportTask()
AssetImportTask.set_editor_property('filename', file)
AssetImportTask.set_editor_property('destination_path', '/Game/Tex')
AssetImportTask.set_editor_property('save', True)
AssetImportTask.set_editor_property('options', options)
import_tasks.append(AssetImportTask)
AssetTools.import_asset_tasks(import_tasks)
2 Likes