Up to date
This page is up to date for Godot 4.3.
If you still find outdated information, please open an issue.
除錯工具概述
本指南將概述引擎中可用的除錯工具.
Godot自帶強大的除錯器和剖析器, 可以追蹤bug, 在運作時檢查你的遊戲, 監控重要指標, 並測量性能. 它還提供了在運作遊戲中視覺化碰撞框和導覽多邊形的選項.
最後, 你可以選擇除錯在遠端裝置上運作的遊戲, 並在遊戲運作時重新載入對你的場景或程式碼的修改.
除錯工具
Godot 的許多除錯工具都是“除錯器”面板的一部分,你可以在 除錯工具 中找到相關資訊。
腳本編輯器除錯工具和選項
腳本編輯器有自己的一套除錯工具,用於中斷點和兩個選項。中斷點工具也可以在除錯器的**除錯器**分頁中找到。
小訣竅
您可以透過點選腳本編輯器左側的裝訂線(行號左側)來建立斷點。將滑鼠懸停在該排水溝上時,您會看到出現一個透明的紅點,點擊放置斷點後,該紅點會變成不透明的紅點。再次點選紅點即可刪除斷點。以這種方式建立的斷點在編輯器重新啟動後仍然存在,即使退出編輯器時未儲存腳本也是如此。
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. You can set a shortcut for it in Editor Settings > Shortcuts > Debugger.
當偵錯器在斷點處中斷時,腳本編輯器的裝訂線中會顯示綠色三角形箭頭。此箭頭指示偵錯器中斷的程式碼行。
測試
In the project settings, there is a Debug category with subcategories which control different things. Enable Advanced Settings to change these settings.
設定
這些都是一些常規的設定,比如將目前的 FPS 列印到**輸出**面板,剖析時的最大函式量等。
File Logging
These settings allow you to log console output and error messages to files.
GDScript
These settings allow you to toggle specific GDScript warnings, such as for unused variables. You can also turn off warnings completely. See GDScript 警告系統 for more information.
Shader Language
These settings allow you to toggle specific shader warnings, such as for unused variables. You can also turn off warnings completely.
Canvas Items
These settings are for canvas item redraw debugging.
形狀
Shapes中你可以調整形狀的顏色, 這些形狀只出現在除錯的目的, 如碰撞和導覽形狀.
遙控場景面板
當在編輯器中運作遊戲時,場景**面板頂部會出現兩個選項,即**遠端**和**本地。當使用**遠端**時,你可以檢查或改變運作專案中的節點參數。
備註
一些與除錯有關的編輯器設定可以在 Editor Settings 內找到, 在 Network > Debug and Debugger 部分.