Debug your mono Godot project

Introduction

After pull request #19201 attached debugging is now working on all supported platforms. The issues that had been stopping debugging on windows have been fixed and we can now set breakpoints, inspect variables, and step through code to our hearts content.

Currently this requires a recent build from master branch, or 3.0.3+.

1. Install VS Code extension:

Click on the Extensions icon in the activities bar (left had side). Search for and install the Mono Debug extension. Close VS Code (some elements will appear only after restarting the application).



2. Configure your project using the Godot Editor:

Check Project Settings -> Mono -> Debugger Agent -> Wait for Debugger . While on the Debugger Agent page note the value specified for Port . Optionally change the Wait Timeout to a larger value (this will give you more time when performing step 4.3 below).



3. Configure your project using VS Code:

Drop-down menu: Debug > Add Configuration > C# Mono . This will create and open your project’s launch.json file. Ensure the profile named Attach has the correct port from step 2.2 above. Click on the debug icon on the activities bar (left hand side) then select Attach from the configuration pull-down (top). If your project has been created by a Godot version before #18949 (this applies to all official releases before 3.0.3) then edit your project’s .csproj file so that all instances of <DebugType>full</DebugType> are changed to <DebugType>portable</DebugType> .



4. Start debugging:

Apply a breakpoint to an interesting location using VS Code. Start your project using the Godot Editor. Switch to the VS Code application and “Start Debugging” either with the F5 key, the green play button on the debugger activity panel or the Debug drop-down menu.



Conclusion

For subsequent debuging sessions on the same project you can simply repeat step 4, but for new projects you will have to start from step 2. To restore normal behaviour for your project you will need to toggle Wait for Debugger from 2.1 above.

Further Reading

You may also enjoy: