How to debug C++ code with breakpoints from visual studio?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By anubha

I was able to put breakpoints and debug the engine code from visual studio using tutorials linked below, so the engine opens from visual studio but as soon as I open any project, I cannot debug anymore from visual studio. Is there a way to debug the C++ modules with breakpoints?

:bust_in_silhouette: Reply From: Zylann

If you don’t specify command line arguments, Godot will launch in Project Manager mode. When you launch a project from there, it closes, which makes the debugger detach.

If you want to debug the editor or a game straight away, you should change the execution directory to be your project’s directory, and add command line arguments, as explained here: Engine core and modules — Godot Engine (stable) documentation in English
(it says “GDB” but it’s the same with Visual Studio, there is a project settings option that lets you specify those arguments).

-e will make Godot run in editor mode. Omitting it will run the game from its main scene.
If the game has no main scene, or if you want to run a particular scene, add its relative path to the command line, like scenes/level1.tscn.

I don’t know if the doc has a section explicitely showing that for Visual Studio, but here is how it looks like in QtCreator for debugging the editor on a project:
enter image description here

Thanks for your answer, now the debugger doesn’t detach as soon as opening project and project opens directly. I could catch the breakpoint on the _bind_methods in my module in C++ but the breakpoints on the methods itself aren’t hit:

code snippet

The breakpoint in _bind_methods() and the constructor is hit, but not inside the process() or UpdateMotionFromInput(), any idea what is going wrong?

anubha | 2020-03-09 10:37

Maybe they aren’t actually called? (I can’t see your snippet)

Zylann | 2020-03-09 18:47

I just read this thread: reddit thread
So I tried running game directly without the editor by removing the -e option and now all breakpoints work :slight_smile:
Will just run the game directly bypassing the editor whenever I need to debug then. Thanks.

anubha | 2020-03-10 05:00