ue python二次开发启动教程+ 导入fbx到指定文件夹

仓库

https://github.com/nils-soderman/vscode-unreal-python.git

nils-soderman/vscode-unreal-python | DeepWiki

参考

(超级方便的)在UE5中执行Python脚本 - 知乎

我的ue4.24不能运行5.7可以

python 复制代码
import unreal

unreal.log("Hello UE5")

vscode要开插件

=================================================================================================================================================

ue也要开插件

Failed to connect to Unreal Engine [Troubleshooting] · nils-soderman/vscode-unreal-python Wiki

连接到 Unreal Engine 失败 [故障排除] · nils-soderman/vscode-unreal-python Wiki --- Failed to connect to Unreal Engine [Troubleshooting] · nils-soderman/vscode-unreal-python Wiki

导入fbx到指定文件夹

python 复制代码
import unreal
import tkinter as tk
from tkinter import filedialog
import os

def import_fbx_with_tk_safe():
    """
    使用 tkinter 弹窗选择 FBX 文件并安全导入
    """
    try:
        # 隐藏主窗口
        root = tk.Tk()
        root.withdraw()
        
        # 打开文件选择对话框
        file_path = filedialog.askopenfilename(
            title="选择FBX文件",
            filetypes=[("FBX files", "*.fbx"), ("All files", "*.*")]
        )
        
        # 销毁根窗口
        root.destroy()
        
        if not file_path or not os.path.exists(file_path):
            unreal.log("未选择有效文件")
            return
        
        # 检查是否是 FBX 文件
        if not file_path.lower().endswith('.fbx'):
            unreal.log(f"文件 {file_path} 不是有效的 FBX 文件")
            return
        
        # 定义目标路径
        destination_path = "/Game/Characters/MainChar/W/Meshes/"
        
        # 创建导入任务
        import_task = unreal.AssetImportTask()
        import_task.set_editor_property('filename', file_path)
        import_task.set_editor_property('destination_path', destination_path)
        import_task.set_editor_property('save', True)
        import_task.set_editor_property('automated', True)
        import_task.set_editor_property('replace_existing', True)
        
        # 执行导入任务
        asset_tools = unreal.AssetToolsHelpers.get_asset_tools()
        asset_tools.import_asset_tasks([import_task])
        
        unreal.log(f"成功导入文件: {os.path.basename(file_path)}")
        unreal.log(f"导入到路径: {destination_path}")
        
    except Exception as e:
        unreal.log(f"导入过程中发生错误: {str(e)}")

# 执行函数
import_fbx_with_tk_safe()

运行结果

可以开启输出日志

相关推荐
Acrelhuang4 分钟前
工商业用电成本高?安科瑞液冷储能一体机一站式解供能难题-安科瑞黄安南
大数据·开发语言·人工智能·物联网·安全
hello 早上好5 分钟前
03_JVM(Java Virtual Machine)的生命周期
java·开发语言·jvm
沐雪架构师6 分钟前
LangChain 1.0 Agent开发实战指南
开发语言·javascript·langchain
tod1136 分钟前
力扣高频 SQL 50 题阶段总结(四)
开发语言·数据库·sql·算法·leetcode
言無咎16 分钟前
从规则引擎到任务规划:AI Agent 重构跨境财税复杂账务处理体系
大数据·人工智能·python·重构
2501_9400078917 分钟前
Flutter for OpenHarmony三国杀攻略App实战 - 战绩记录功能实现
开发语言·javascript·flutter
naruto_lnq18 分钟前
C++中的桥接模式
开发语言·c++·算法
无限进步_19 分钟前
面试题 02.02. 返回倒数第 k 个节点 - 题解与详细分析
c语言·开发语言·数据结构·git·链表·github·visual studio
张小凡vip21 分钟前
数据挖掘(十)---python操作Spark常用命令
python·数据挖掘·spark
布谷歌27 分钟前
面试题整理
java·开发语言