1 新建項目,開啓插件
2 項目設置—>Python
3 資源加載腳本 AssetFunctions.py(目錄跟上圖的目錄一致)
導入FBX
import unreal
asset_path = "E:/fireAxe.FBX"
asset_path2 = "E:/fireAxe2.FBX"
def ImportMyAssets():
asset_task = buildImportTask(asset_path,'/Game/Object')
asset2_task = buildImportTask(asset_path2, '/Game/Object')
executeImportTasks([asset_task,asset2_task])
# https://api.unrealengine.com/INT/PythonAPI/class/AssetToolsHelpers.html
def buildImportTask(filename,destination_path):
task = unreal.AssetImportTask()
task.set_editor_property('automated',True)
task.set_editor_property('destination_name', '')
task.set_editor_property('destination_path', destination_path)
task.set_editor_property('filename',filename)
task.set_editor_property('replace_existing',False)
task.set_editor_property('save',False)
return task
# https://api.unrealengine.com/INT/PythonAPI/class/AssetTools.html
def executeImportTasks(tasks):
unreal.AssetToolsHelpers.get_asset_tools().import_asset_tasks(tasks)
4 依次執行
import AssetFunctions as AF
AF.ImportMyAssets()
5 然後,素材自動導入到項目中
導入音頻和圖片
import unreal
texture_tga = "E:/Test/Img.TGA"
sound_wav = "E:/Test/bgm.WAV"
def importMyAssets():
sound_task = buildImportTask(sound_wav, '/Game/Sounds')
texture_task = buildImportTask(texture_tga, '/Game/Textures')
executeImportTasks([sound_task, texture_task])
def buildImportTask(filename, destination_path):
task = unreal.AssetImportTask()
task.set_editor_property('automated', True)
task.set_editor_property('destination_name', '')
task.set_editor_property('destination_path', destination_path)
task.set_editor_property('filename', filename)
task.set_editor_property('replace_existing', True)
task.set_editor_property('save', True)
return task
def executeImportTasks(tasks):
unreal.AssetToolsHelpers.get_asset_tools().import_asset_tasks(tasks)