0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

VSCodeでLSPにPyreflyを使ってUnrealEngineのPythonを開発する

Posted at

Pyreflyとは

簡単に言うとMeta社(旧Facebook)が作ったRust製のツール
詳しくは上記の記事参照

2025/10/30時点ではPyreflyはまだα版です。
不具合なども考慮して使ってください

β版のリリースは上記のIssueを参照してください

なぜPyreflyを使うの?

UE5で作成されるPythonStubファイルはUE5で読み込まれているモジュール分すべてのUSTRUCTやUCLASSを参照します。
UE5はエンジンのバージョンアップ毎にモジュールが増え続けています。
フォーラムの記事やPylanceのIssueを見るとPylanceでは読み込めるスタブファイルの複雑度に限界があるようです。
UE5本体とアプリケーション側のモジュールを合計するとPylanceの認識できるスタブのサイズを超えてしまう事があります。

Pylance Pyrefly
image.png image.png

また、PylanceよりPyreflyの方が情報量が多いです。
上記の例だと、Pylanceだと Array | None と認識されますが、Pyreflyだと Array[AssetData] | Noneと認識されます。
Pylanceだとfor文の変数の型を認識してくれないので入力補完が効かないのでPyreflyの方が使いやすいと思います

導入方法

公式ドキュメント

プロジェクトルートフォルダ
  - Intermediate
    - PythonStub
      - unreal.py"
  - Content
    - Python
  - プロジェクト名.uproject

上記のフォルダ構成でプロジェクトルートフォルダ/Content/PythonをVSCodeのワークスペースとして開く想定で話します

image.png

VSCodeの拡張機能タブでPyreflyと入力してPyrefly - Python Language Toolingをインストールしてください。

To avoid conflicts, you should disable other Python language servers by either setting "Language Server: None" in the extension settings or by disabling the Pyright or BasedPyright extensions.
競合を避けるため、他のPython言語サーバーを無効化してください。方法としては、拡張機能設定で「言語サーバー: なし」を設定するか、PyrightまたはBasedPyright拡張機能を無効化します。

image.png

競合を避ける為にPylanceの拡張機能を無効化します

image.png

続いてPython拡張機能設定の言語サーバーをNoneに変更してください

pyrefly.toml
python-version = "3.12"
search_path = [
    "./../../Intermediate/PythonStub"
]

続いてPyreflyの設定ファイルを書きます
ワークスペースルートにpyrefly.tomlを作成して、PythonStubへのパスを相対パスで記述してください。
以上でunrealモジュールを認識するはずなのでLSPが動作するようになります

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?