1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

UnrealEditor で Python をデバッグする方法

Last updated at Posted at 2025-05-16

はじめに

UE5.3 から、Python を使う時にデバッグ方法です。

とりあえず、Python 系の Plugin を有効にします

image.png

設定

Unreal プロジェクト は、Config/DefaultEngine.ini
Unreal Plugin は、 Config/Engine.ini
に下記の設定を追加します。

Engine.ini
[/Script/PythonScriptPlugin.PythonScriptPluginSettings]
+StartupScripts=EditorStartup.py
bIsolateInterpreterEnvironment=False
bDeveloperMode=True
bRemoteExecution=False
RemoteExecutionMulticastGroupEndpoint=239.0.0.1:6766
RemoteExecutionMulticastBindAddress=127.0.0.1
RemoteExecutionSendBufferSizeBytes=2097152
RemoteExecutionReceiveBufferSizeBytes=2097152
RemoteExecutionMulticastTtl=0

Content/Python/EditorStartup.py
が UnrealEditor 起動時に呼ばれます。
Python デバッグする為に、
bIsolateInterpreterEnvironment=False
を設定する必要があります。

Python ワークスペース

Python のソースコードは、
Content/Python に置きます

Python のフォルダ構造
image.png

EditorStartup.py、Test.py を下記のように記述します。

EditorStartup.py
# Content/Python/EditorStartup.py  ― Editor 起動時に 1度だけ走らせる
import os, sys, unreal, pathlib

# Engine に同梱されている “本物” の python.exe を取得
engine_dir = unreal.Paths.engine_dir()             # 例: C:/Epic Games/UE_5.3/Engine/
py_exe = os.path.join(
    engine_dir, "Binaries", "ThirdParty", "Python3", "Win64", "python.exe"
)

# まだ差し替えていなければ上書き
if sys.executable.lower().endswith("unrealeditor.exe") and os.path.isfile(py_exe):
    sys.executable = py_exe

# 以降で debugpy を読み込むと、adapter は python.exe で起動する
import debugpy

if not getattr(debugpy, "_listening", False):
    debugpy.listen(("0.0.0.0", 5678))
    debugpy._listening = True
    unreal.log("debugpy listening on 5678 in main editor process…")
Test.py
import unreal

_conunter = 0

def test_func():
    global _conunter
    _conunter += 1
    unreal.log(f"test_func: {_conunter}")

.vscode/launch.json を下記のように記述します

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Attach to Unreal Python",
            "type": "debugpy",
            "request": "attach",
            "connect": {
                "host": "127.0.0.1",
                "port": 5678
            },
            "pathMappings": [
                {
                    "localRoot": "${workspaceFolder}",
                    "remoteRoot": "${workspaceFolder}"
                }
            ],
        }
    ]
}

UnrealEditor を起動します

VSCode の実行ボタン(Attach to Unreal Python)を押します

image.png

Unreal から、Test.py の test_func() を呼び出します

OutputLog から Cmd => Python に切り替えて、Test.test_func を呼び出す方法
image.png

BluePrint から Test.test_func を呼び出す方法
image.png

import Test
Test.test_func()

image.png

Test.py のブレークポイント止まりました

_counter 変数の ウォッチもできています。
image.png

補足 Test.py の編集が反映されない場合

OutputLog の Python から、または、ブループリントから
下記のコードを呼び出してください

import sys

if "Test" in sys.modules:
    del sys.modules["Test"]
1
2
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
1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?