Visual Studio Code¶
Visual Studio Code is a free cross-platform code editor by Microsoft (not to be confused with Visual Studio).
匯入專案¶
Make sure the C/C++ extension is installed. You can find instructions in the official documentation. Alternatively, clangd can be used instead.
When using the clangd extension, run
scons compiledb=yes
.從 Visual Studio Code 的主畫面中通過 檔案 > 開啟資料夾... 來開啟 Godot 根目錄。
按一下 Ctrl + Shift + P 來開啟命令選擇區,並輸入 Configure Task (設定工作)。

選擇 從範本建立 tasks.json 檔案 選項。

接著選擇 Others 。

在
tasks.json
檔案中,找到"tasks"
陣列,並在其中新增一段新的內容:
{
"label": "build",
"group": "build",
"type": "shell",
"command": "scons",
"args": [
"-j $(nproc)"
],
"problemMatcher": "$msCompile"
}
{
"label": "build",
"group": "build",
"type": "shell",
"command": "scons",
"args": [
// Use this when your default shell is Command Prompt (cmd.exe).
"-j %NUMBER_OF_PROCESSORS%",
// Use this when your default shell is PowerShell.
"-j $env:NUMBER_OF_PROCESSORS"
],
"problemMatcher": "$msCompile"
}

填寫 tasks.json
的範例。¶
依據各種不同的設定與需求,可以使用不同的引數。有關完整的引數列表,請參考 建置系統簡介 。
對專案進行除錯¶
要執行並對專案進行除錯,則需要在 launch.json
檔案中建立一個新的設定。
按一下 Ctrl + Shift + D 來開啟 [執行] 面板。
若沒有
launch.json
檔案,則會顯示建立新檔案的提示。

選擇 C++ (GDB/LLDB) 。此處可能會出現其他平台特定的選項。選擇後,請依據提供的範例來調整設定。
在
launch.json
檔案中,找到"configurations"
陣列並在其中新增一段新的內容:
{
"name": "Launch Project",
"type": "lldb",
"request": "launch",
// Change to godot.x11.tools.64.llvm for llvm-based builds.
"program": "${workspaceFolder}/bin/godot.x11.tools.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.x11.tools.64.llvm for llvm-based builds.
"program": "${workspaceFolder}/bin/godot.x11.tools.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.tools.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"
}

填寫 launch.json
的範例。¶
備註
Due to sporadic performance issues, it is recommended to use LLDB over GDB on Unix-based systems. Make sure that the CodeLLDB extension is installed.
If you encounter issues with lldb, you may consider using gdb (see the X11_gdb configuration).
Do note that lldb may work better with llvm-based builds. See 為 X11 進行編譯 (Linux, *BSD) for further information.
在 program
中的名稱會依據建置設定而有所不同,如有開啟 tools
的 64 位元 X11 版為 godot.x11.tools.64
。
若遇到任何問題,請在 任何一個 Godot 的社群頻道 中尋求幫助。