Up to date
This page is up to date for Godot 4.2
.
If you still find outdated information, please open an issue.
Visual Studio Code¶
Visual Studio Code 是由 Microsoft 提供的免費跨平台 IDE (請不要與 Visual Studio 搞混)。
匯入專案¶
請確定有安裝 C/C++ 延伸模組。可以在 官方說明文件 (英語) 中瞭解詳細說明。
使用 clangd 擴充時,請執行
scons compiledb=yes
。從 Visual Studio Code 的主畫面中通過 檔案 > 開啟資料夾... 來開啟 Godot 根目錄。
按一下 Ctrl + Shift + P 來開啟命令選擇區,並輸入 Configure Task (設定工作)。
選擇 從範本建立 tasks.json 檔案 選項。
接著選擇 Others 。
如果沒有「從範本建立tasks.json檔案」這樣的選項可用,請刪除該檔案(如果資料夾中已存在該檔案)或手動建立「.vscode/tasks.json」檔案。有關工作的更多詳細信息,請參閱“Visual Studio Code 中的工作 <https://code.visualstudio.com/docs/editor/tasks#_custom-tasks>”。
在
tasks.json
檔案中,找到"tasks"
陣列,並在其中新增一段新的內容:{ "label": "build", "group": "build", "type": "shell", "command": "scons", "args": [ // enable for debugging with breakpoints "dev_build=yes", ], "problemMatcher": "$msCompile" }
依據各種不同的設定與需求,可以使用不同的參數。有關完整的參數列表,請參考 建置系統簡介 。
對專案進行除錯¶
要執行並對專案進行除錯,則需要在 launch.json
檔案中建立一個新的設定。
按一下 Ctrl + Shift + D 來開啟 [執行] 面板。
若沒有
launch.json
檔案,則會顯示建立新檔案的提示。
選擇 C++ (GDB/LLDB) 。此處可能會出現其他平台特定的選項。選擇後,請依據提供的範例來調整設定。
在
launch.json
檔案中,找到"configurations"
陣列並在其中新增一段新的內容:
{
"name": "Launch Project",
"type": "lldb",
"request": "launch",
// Change to godot.linuxbsd.editor.dev.x86_64.llvm for llvm-based builds.
"program": "${workspaceFolder}/bin/godot.linuxbsd.editor.dev.x86_64",
// Change the arguments below for the project you want to test with.
// To run the project instead of editing it, remove the "--editor" argument.
"args": [ "--editor", "--path", "path-to-your-godot-project-folder" ],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"preLaunchTask": "build"
}
{
"name": "Launch Project",
"type": "cppdbg",
"request": "launch",
// Change to godot.linuxbsd.editor.dev.x86_64.llvm for llvm-based builds.
"program": "${workspaceFolder}/bin/godot.linuxbsd.editor.dev.x86_64",
// Change the arguments below for the project you want to test with.
// To run the project instead of editing it, remove the "--editor" argument.
"args": [ "--editor", "--path", "path-to-your-godot-project-folder" ],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"setupCommands":
[
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "build"
}
{
"name": "Launch Project",
"type": "cppvsdbg",
"request": "launch",
"program": "${workspaceFolder}/bin/godot.windows.editor.dev.x86_64.exe",
// Change the arguments below for the project you want to test with.
// To run the project instead of editing it, remove the "--editor" argument.
"args": [ "--editor", "--path", "path-to-your-godot-project-folder" ],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"console": "internalConsole",
"visualizerFile": "${workspaceFolder}/platform/windows/godot.natvis",
"preLaunchTask": "build"
}
備註
由於偶然的性能問題,建議在基於Unix的系統上使用LLDB而不是GDB。確保 CodeLLDB extension 已經安裝。
如果遇到lldb的問題,你可以考慮使用gdb,參閱X11_gdb配置。
請注意,lldb可能在基於llvm的建構中工作得更好。參閱 doc_compiling_for_x11 以瞭解更多資訊。
在 program
中的名稱會依據建置設定而有所不同,如有開啟 tools
的 64 位元 X11 版為 godot.x11.tools.64
。
若遇到任何問題,請在 任何一個 Godot 的社群頻道 中尋求幫助。
小訣竅
安裝 VSMonoDebugger 擴充套件 。