Attention: Here be dragons
This is the latest
(unstable) version of this documentation, which may document features
not available in or compatible with released stable versions of Godot.
Checking the stable version of the documentation...
Visual Studio Code
备注
This documentation is for contributions to the game engine, and not using Visual Studio Code as a C# or GDScript editor. To code C# or GDScript in an external editor, see the C# guide to configure an external editor or the GDScript guide to using an external text editor.
Visual Studio Code 是微软推出的免费跨平台代码编辑器(请勿与 Visual Studio 混淆)。
导入项目
使用 clangd 扩展时,请执行
scons compiledb=yes
。现在在VS Code中打开克隆的godot文件夹 文件 > 打开文件夹... .
按 Ctrl + Shift + P 打开命令提示符窗口,然后输入 Configure Task。

选择 Create tasks.json file from template 选项。

然后选择其他。

If there is no such option as Create tasks.json file from template available, either delete the file if it already exists in your folder or create a
.vscode/tasks.json
file manually. See Tasks in Visual Studio Code for more details on tasks.在
tasks.json
文件中找到"tasks"
数组, 并在其中添加一个新部分:.vscode/tasks.json{ "label": "build", "group": "build", "type": "shell", "command": "scons", "args": [ // enable for debugging with breakpoints "dev_build=yes", ], "problemMatcher": "$msCompile" }

填好了 tasks.json
的一个例子.
参数可以根据你自己的设置和需要而不同. 参见 构建系统介绍 以获取完整的参数列表.
调试项目
为了构建项目, 我们需要配置文件 launch.json
.
按 Ctrl + Shift + D 打开“运行”面板。
如果缺少
launch.json
文件, 系统会提示你创建一个新的文件.

Select C++ (GDB/LLDB). There may be another platform-specific option here. If selected, adjust the configuration example provided accordingly.
在
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
},
{
"description": "Load custom pretty-printers for Godot types.",
"text": "source ${workspaceRoot}/misc/utility/godot_gdb_pretty_print.py"
}
],
"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"
}
{
"name": "Launch Project",
"type": "lldb",
"request": "launch",
"program": "${workspaceFolder}/bin/godot.macos.editor.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"],
"cwd": "${workspaceFolder}",
"preLaunchTask": "build"
}
{
"name": "Launch Project",
"type": "lldb",
"request": "launch",
"program": "${workspaceFolder}/bin/godot.macos.editor.arm64",
// 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"],
"cwd": "${workspaceFolder}",
"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 for configurations using lldb.
If you encounter issues with lldb, you may consider using gdb (see the LinuxBSD_gdb configuration).
Do note that lldb may work better with LLVM-based builds. See 为 Linux、*BSD 平台编译 for further information.
The name under program
depends on your build configuration,
e.g. godot.linuxbsd.editor.dev.x86_64
for 64-bit LinuxBSD platform with
target=editor
and dev_build=yes
.
Configuring Intellisense
For the C/C++ extension:
To fix include errors you may be having, you need to configure some settings in the c_cpp_properties.json
file.
First, make sure to build the project since some files need to be generated.
Edit the C/C++ Configuration file either with the UI or with text:

Add an include path for your platform, for example,
${workspaceFolder}/platform/windows
.Add defines for the editor
TOOLS_ENABLED
, debug buildsDEBUG_ENABLED
, and testsTESTS_ENABLED
.Make sure the compiler path is configured correctly to the compiler you are using. See 构建系统介绍 for further information on your platform.
c_cpp_properties.json
文件在 Windows 系统下应该类似于这样:.vscode/c_cpp_properties.json{ "configurations": [ { "name": "Win32", "includePath": [ "${workspaceFolder}/**", "${workspaceFolder}/platform/windows" ], "defines": [ "_DEBUG", "UNICODE", "_UNICODE", "TOOLS_ENABLED", "DEBUG_ENABLED", "TESTS_ENABLED" ], "windowsSdkVersion": "10.0.22621.0", "compilerPath": "C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.39.33519/bin/Hostx64/x64/cl.exe", "cStandard": "c17", "cppStandard": "c++17", "intelliSenseMode": "windows-msvc-x64" } ], "version": 4 }
你也可以使用 scons 参数
compiledb=yes
并将编译命令设置compileCommands
设置为compile_commands.json
,该设置可以在 C/C++ 配置界面的高级部分找到。This argument can be added to your build task in
tasks.json
since it will need to be run whenever files are added or moved.
如果遇到问题, 也可在 Godot 社区论坛 中寻求帮助.
小技巧
To get linting on class reference XML files, install the vscode-xml extension.