调试工具概述
本指南将概述引擎中可用的调试工具.
Godot自带强大的调试器和剖析器, 可以追踪bug, 在运行时检查你的游戏, 监控重要指标, 并测量性能. 它还提供了在运行游戏中可视化碰撞框和导航多边形的选项.
最后, 你可以选择调试在远程设备上运行的游戏, 并在游戏运行时重新加载对你的场景或代码的修改.
调试器面板
Godot 的许多调试工具都是“调试器”面板的一部分,你可以在 调试器面板 中找到相关信息。
调试菜单选项
在编辑器中运行游戏时, 有几个常见的调试选项可以切换为开或关, 以帮助你调试游戏.
你可以在编辑器菜单调试中找到这些选项。
下面是这些选项的说明:
使用远程调试部署
When this option is enabled, using one-click deploy will make the executable attempt to connect to this computer’s IP so the running project can be debugged. This option is intended to be used for remote debugging (typically with a mobile device). You don’t need to enable it to use the GDScript debugger locally.
使用网络文件系统进行小型部署
这个选项加快了在远程设备上进行大足迹游戏的测试.
When Small Deploy with Network Filesystem is on, instead of exporting the full game, deploying the game builds a minimal executable. The editor then provides files from the project over the network.
另外,在 Android 系统上,游戏采用 USB 线部署,加快部署速度。
显示碰撞区域
When this option is enabled, collision shapes and raycast nodes (for 2D and 3D) will be visible in the running project.
显示路径
启用该选项时,路径节点的曲线资源将在项目运行时可见。
显示导航
启用该选项时,导航网格和多边形将在项目运行时可见。
显示避障
启用该选项时,避障对象的形状、半径、速度都将在项目运行时可见。
调试 CanvasItem 重绘
启用该选项时,2D 对象的重绘请求将在项目运行时可见(短暂的闪光)。可用于低处理器模式下的故障排除。
同步场景修改
启用该选项时,在编辑器中对场景的任何修改都会被应用于正在运行的项目中。当使用于远程设备时,启用网络文件系统能提高编辑效率。
同步脚本修改
启用该选项时,任何保存的脚本都会被正在运行的项目重新加载。当使用于远程设备时,启用网络文件系统能提高编辑效率。
调试服务器保持开放
启用该选项时,编辑器的调试服务器将保持开放,监听在编辑器本身之外开始的新会话。
自定义运行实例…
This opens a dialog allowing you to tell Godot to run multiple instances of the game at once, and to specify the command line arguments for each instance. This is especially useful when building and debugging multiplayer games.
启用多实例
When this option is enabled, the editor will run multiple instances of the project at once when you Run Project.
Below this checkbox is a selector to pick how many instances to run.
Checking the box and setting this to only 1 is the same as not checking this box at all.
主要运行参数
These are the arguments that will be passed to every instance of the project when you Run Project, unless you select “Enabled” under “Override Main Run Args” for a specific instance.
Note that these arguments are space-separated.
小技巧
These arguments can be accessed in your script by using get_cmdline_args.
警告
Even if you uncheck “Enable Multiple Instances” these arguments will be passed when you Run Project.
主要特性标签
These are the feature tags that will be passed to every instance of the project when you Run Project, unless you select “Enabled” under “Override Main Tags” for a specific instance.
覆盖主要运行参数
When this is enabled, the arguments in the “Main Run Args” field will not be passed to this specific instance of the project when you Run Project.
Launch Arguments
These are the arguments that will be passed to this specific instance of the project when you Run Project. They will be combined with the “Main Run Args” unless you select “Enabled” under “Override Main Run Args”.
Override Main Tags
When this is enabled, the tags in the “Main Feature Tags” field will not be passed to this specific instance of the project when you Run Project.
Feature Tags
These are the feature tags that will be passed to this specific instance of the project when you Run Project. They will be combined with the “Main Feature Tags” unless you select “Enabled” under “Override Main Tags”.
警告
If you want to pass “User” arguments, that can be accessed with get_cmdline_user_args then you must prefix them with two dashes and a space like -- one two three.
Be aware that these dashes will apply to arguments added later in the “Launch Arguments” on a per instance basis, which can cause some confusion when combining the Main Run Args and Launch Arguments.
If you place -- one two three in the “Main Run Args” and -- four five six in the “Launch Arguments” then the final command line arguments will be one two three — four five six. This is because the -- is repeated in the “Launch Arguments”.
脚本编辑器调试工具和选项
脚本编辑器有自己的一套调试工具,用于断点和两个选项。断点工具也可以在调试器的调试器选项卡中找到。
小技巧
You can create a breakpoint by clicking the gutter in the left of the script editor (on the left of the line numbers). When hovering this gutter, you will see a transparent red dot appearing, which turns into an opaque red dot after the breakpoint is placed by clicking. Click the red dot again to remove the breakpoint. Breakpoints created this way persist across editor restarts, even if the script wasn’t saved when exiting the editor.
You can also use the breakpoint
keyword in GDScript to create a breakpoint that is stored in the script itself. Unlike breakpoints created by clicking in the gutter, this keyword-based breakpoint is persistent across different machines when using version control.
断点 按钮会像断点一样导致脚本的中断. 继续 使游戏在断点处暂停后继续. Step Over 进入下一行代码, 如果可能的话, Step Into 进入一个函数. 否则, 它与 Step Over 做同样的事情.
The Debug with External Editor option lets you debug your game with an external editor. This option is also accessible in Editor Settings > Debugger.
When the debugger breaks on a breakpoint, a green triangle arrow is visible in the script editor’s gutter. This arrow indicates the line of code the debugger broke on.
调试项目设置
在项目设置中有一个 Debug(调试)类别,包含三个子类别,可以控制不同的东西。
Settings(设置)
这些都是一些常规的设置,比如将当前的 FPS 打印到输出面板,剖析时的最大函数量等。
GDScript
这些设置允许你切换特定的GDScript警告, 比如未使用的变量. 你也可以完全关闭警告.
Shapes(形状)
Shapes中你可以调整形状的颜色, 这些形状只出现在调试的目的, 如碰撞和导航形状.
遥控场景面板
当在编辑器中运行游戏时,场景面板顶部会出现两个选项,即远程和本地。当使用远程时,你可以检查或改变运行项目中的节点参数。
备注
一些与调试有关的编辑器设置可以在 Editor Settings 内找到, 在 Network > Debug and Debugger 部分.