2
votes

I'm really interested in godot as game engine and the possibilities to use c++ to develop in it. I've stopped on gdnative approach, because it faster and easier (and also gives me a possibility to work with CMake instead of SCons). I've already arranged small project based on gdnative_cpp_example with the only difference that I used Cmake instead of Scons (gladly godot-cpp, which is used for generating bindings, alongside SConstruct have CMakeLists script in it). Only problem I left with, is the absence of good way to debug c++ and gdscript code. For development I use vs code (on windows), and for now I've found 3 ways to debug:

  1. I can start project directly from vs code, slightly modifying "Launch" configuration, to start godot editor with --project argument. This gives ability to debug c++, but not gdscript.
  2. With godot-tools extension for vs code I can use last to debug gdscript, but not c++..
  3. I can start the project from editor (which will give me ability to debug gdscript), and after that attach vs code debugger to a running process to debug c++ dll. This works, but I need directly attach vs code by choosing correct process only after I've launched this process. Because of that I miss initialization time, and it's also feels clunky..

Ultimately I want to debug gdscript and c++ dll within vs code at the same time, but I'm not sure that it's even possible.. So what will be good is to have ability to start game process from the editor and automatically connect vs code to it. I've tried to search something like "vs code automatic c++ debug", but I haven't found anything on web. Maybe I am just searching for incorrect term. Does anyone know anything on this topic?

(I've tried to keep my question short, but I'm not sure I've made it well informative, so feel free to ask questions)

1

1 Answers

2
votes

If you came here for the automatic debugger start, then maybe tenfour's comment on the question could help you, but because main reason for this question was little bit different (find the way to debug godot projects with both c++ and gdscript at the same time), I've found different solution, so if someone came here for the same reason, here what I came up with. First you need correctly setup c++ project in vscode, which will compile your gdnative dll from godot-cpp project and your personal code (I suggest to use CMake for all of this, as I said godot-cpp can work with CMake). Second: you need godot-tools plagin to your vscode. After everything working correctly, dll is compiling and godot project is using it, you need to setup next launch configuration:

{
    // this must be in .vscode/launch.json
    "version": "0.2.0",
    "configurations": [
        {
            "name":"godot-gdscript-attach",
            "type": "godot",
            "request": "launch",
            "project": "${workspaceFolder}/project/",
            "port": 6007,
            "address": "127.0.0.1",
            "launch_game_instance": false,
            "launch_scene": false
        },
        {
            "name": "godot-cpp-launch",
            "type": "cppvsdbg",
            "request": "launch",
            "program": "${config:godot_tools.editor_path}",
            "args": [
                "--debug",
                "--remote-debug", 
                "127.0.0.1:6007",
                "--path", 
                "\"${workspaceFolder}/project/\""
            ],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}/project/",
            "environment": [],
            "externalConsole": true
        }
    ],
    "compounds": [
        {
            "name": "godot-launch",
            "configurations": [
                "godot-gdscript-attach",
                "godot-cpp-launch"
            ]
        }
    ]
}
  • godot-gdscript-attach after start will wait for godot game to connect as debug target on ip/port = 127.0.0.1:6007 (this will work even if you start this configuration, and after that launch game from editor).
  • godot-cpp-launch will launch your game as debug target for cppvsdbg (as I understand this is vs debugger). Little bit more info on this one:
    • "program": "${config:godot_tools.editor_path}" <- this is what program must be ran for debuging. I have here config:godot_tools.editor_path as path because it's option which is setuped for godot-tools. Nothing special, just convinient, so I can now change godot path for both godot-tools and my debug configs at the same time.
    • argument "127.0.0.1:6007" <- this is ip and port for which godot will look at the start to connect for gdscript debugging. You can see the same values is written for "address"/"port"
    • --path ${workspaceFolder}/project/ <- this is project folder. My project placed in "project" folder within my vscode project, if your project in a different folder, configure it's here.

After that you can run godot-launch as a configuration in vs code. This will startup your project and connect both of your debuggers (c++ debugger and gdscript one) to it. Both type of breakpoints will work.