Reimport Asset through Python

Need some help with how to reimport an asset from python.

My asset importer imports an fbx to a temp folder then moves all the assets to their proper location once it figures out the proper naming.
This works great unless the asset already exists. Then it errors saying asset exists so I thought for those cases I’d just reimport on the existing asset. However I can’t find any way to force an asset reimport.

Anybody have this working?

OK I think I got it:
It wasn’t clear that the import task could target a specific imported asset without reimporting everything, so just resuing the import task seems to be working.

I have the same problem as you had years ago @straightdiesel . can you explain me more, what to you mean by reusing import task?

reusing this function doesn’t seems to work and re-import existing assets.
Thank you

This works for me.

import unreal

def reimport_asset(asset_path):

#Return Object(child of _ObjectBase) Class
asset = unreal.EditorAssetLibrary.load_asset(asset_path) 

import_data = asset.get_editor_property("asset_import_data")
#Get fbx path, Ex: 'e:\dev\Player\Animation\Export\PE\A_Pl_Base_005.fbx'
fbx_file_path = import_data.get_first_filename()

import_task = unreal.AssetImportTask()
#Important! Need to assgin fbx path to filename. 
import_task.filename = fbx_file_path 

#get_name() is a class method in _ObjectBase Class
import_task.destination_name = asset.get_name() 
import_task.destination_path = asset.get_path_name().rpartition("/")[0]
#Ignore pop-up window
import_task.replace_existing = True 

asset_tools = unreal.AssetToolsHelpers.get_asset_tools()
asset_tools.import_asset_tasks([import_task])

asset_path = ‘/Game/Player/Base/Animation/A_Pl_Base_PE_005’

reimport_asset(asset_path)

1 Like