Download

Python: Getting the source file of a texture map

Hi,

I’m trying to get the source file of a texture map asset via python. I can get all the Texture2D maps, but I am not sure how to get the source file. I saw that there is an AssetImportData and asset_import_data flag or command, but I am not sure how to use them, or if they work on an asset.

Also, I often have to dig around to get clarity on python command usage for unreal. is there a way to query examples/flags etc in the python command prompt in Unreal?



asset_registry = unreal.AssetRegistryHelpers.get_asset_registry()
all_assets = asset_registry.get_assets_by_path('/Game', recursive=True)
for asset in all_assets:
    if asset.asset_class == 'Texture2D':
        print asset.asset_name
        print asset.object_path
        print unreal.AssetImportData(asset)
        print asset_import_data = asset.asset_import_data()


Thank you.

Adnan Hussain

I usually do this if I have selected an asset in the content browser


assets = unreal.EditorUtilityLibrary.get_selected_assets()
unreal.log(assets[0].get_editor_property("asset_import_data").get_first_filename())

Based on your code you will need to go from AssetData to the main asset object then “get_editor_property(“asset_import_data”).get_first_filename()”