type
status
date
slug
summary
tags
category
icon
password
首先在 Unreal Editor 内打开 Editor Preferences,然后找到 Python 一栏,打开 Developer Mode:

重启编辑器,可以发现在 ${ProjectDir}/Intermediate/PythonStub 下生成了一个 unreal.py 文件,这个是 UE 自动生成的 python 类接口文件,我们可以用它来做 PyCharm 的代码提示源。
接下来打开 PyCharm,进入设置,找到 Python Interpreter 页签,然后点击 Add Interpreter,选择 Add Local Interpreter:

接着选 Existing,添加 /Engine/Binaries/ThirdParty/Python3/Win64/python.exe:

然后在上一级界面的下拉框里选 Show All:

然后选择依次点击按钮,把刚刚生成的 PythonStub 目录添加到列表中:

最后在 PyCharm 菜单栏中依次点击 Help → Edit Custom Properties,然后在弹出的文件中添加如下两行:
这是因为 unreal.py 文件巨大, 默认情况下 PyCharm 不会进行文件索引,配上这两行就好了,最后重启 PyCharm,即可在 python 文件中获取 unreal module 的代码提示。
PS: Rider 也可以按照类似的方法配置,不过要先在 IDE 内安装 Python 插件。
参考资料
- 作者:Kindem
- 链接:https://www.flyandnotdown.com/post/14a8fb78-2f78-80d1-8200-f391ce18e3e0
- 声明:本文采用 CC BY-NC-SA 4.0 许可协议,转载请注明出处。