Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can I setup the C# debugger with Godot? Cannot stop on breakpoints #12

Closed
hs1955 opened this issue May 5, 2024 · 1 comment
Closed

Comments

@hs1955
Copy link

hs1955 commented May 5, 2024

Hello everyone! This may be a noob question as I'm new to Godot and flatpak (and I use Ubuntu). I'm having some difficulty setting up the C# debugger with godot; I can't configure it to stop on breakpoints.

If I set breakpoints in the Godot Script Editor, my debugger will not stop on them.

I've also tried using VSCode as my script editor (I would prefer using that if I can), I setup vscode in the godot settings as described in the Readme, with flatpak-spawn --host. I've tried using a variety of launch configurations, but none of them would stop on the breakpoints. VSCode tells me that 'no debug symbols could be found' when I hover over the breakpoint, but when I check the directory where I built my game, I can see the 'game.pdb' is in the same directory as my 'game.dll'.

I have managed to setup C# debugging before by manually installing Godot from the website, but I want to use this flatpak for the automatic updating. I also want to make sure that this issue isn't related to flatpak sandboxing. I had a brief read of the other open issue: #2 but I cannot tell if this is related or not.

I've also tried reinstalling my dotnet installation, but still no luck. I think the root of the problem is that Godot just isn't stopping on breakpoints.

So I'm not too sure what's going on here. Has anyone got a C# debugging setup with this flatpak?

@hs1955
Copy link
Author

hs1955 commented May 30, 2024

I've figured out how to setup debugging on C# godot now. I'll leave this comment here for posterity, in case someone else, especially newcomers, get stuck with setting up C# Godot debugging. To anyone struggling with getting this setup, don't worry - follow these steps and good luck!

Note this answer applies to both the tar version of .NET Godot and this flatpak. But if you're new to .NET Godot, this comment also has general useful info to know-how, even if your not using this specific flatpak godot.

But quickly for newbies to flatpak, a flatpak is a containerized application, which contains its own packages with their own versions, so it can reliably run. Flatpaks run in the 'flatpak sandbox', or basically with restricted permissions/access to the rest of your files. Luckily, all that means for setting up C# debugging with this Godot flatpak, is explained here in the README for this flatpak: https://github.com/flathub/org.godotengine.GodotSharp#using-an-external-script-editor


Firstly, I learnt that Godot's in-built editor does not support C# debugging, and it was never intended to: godotengine/godot#37691 (comment)

So the C# Godot Editor will always skip breakpoints and/or has little autocompletion/IDE support. It was always intended to that you'll use editors that already have great C# support, so pick your favourite C# editor.

I'll use VSCode with extensions here for the rest of this answer, but any IDE that supports C# can be used.


1) Ensure that the latest dotnet is installed properly and working.

Here's the version I used, but the latest should do, even from the Ubuntu repositories. Completely uninstall and reinstall dotnet and sort out your repos for Linux (Ubuntu) users if you have to:

❯ dotnet --version
8.0.105

2) Install and ensure that your C# Dev Kit Extension is working properly.

To check its working, try running the .NET new project command, or checking if you have intellisense. See here if you get any problems:

Here's the repo for other issues related to this extension

The C# dev kit alone should be enough to give you intellisense even for Godot projects. Now open Godot, and configure it to use VSCode. This step is pretty easy, but in case you're struggling:

3) I recommend installing the: Godot .NET Tools VSCode Extension.

Then run the command Godot .NET: Generate files for godot project. This will generate the correct launch.json launch task and tasks.json build task. You should not need to edit these. But in case your in doubt, this is the launch.json I used to run C# godot with debugging and breakpoints (this extension should generate exactly this as well):

{
	"version": "0.2.0",
	"configurations": [
		{
			"name": "Launch", // <-- This is the configuration that worked for me
			"type": "coreclr",
			"request": "launch",
			"program": "${config:godot-dotnet-tools.executablePath}",
			"preLaunchTask": "build",
			"args": [
				"--path",
				"${workspaceRoot}"
			],
			"cwd": "${workspaceFolder}",
			"console": "internalConsole",
			"stopAtEntry": false
		},
		{
			"name": "Launch Editor",
			"type": "coreclr",
			"request": "launch",
			"program": "${config:godot-dotnet-tools.executablePath}",
			"preLaunchTask": "build",
			"args": [
				"--path",
				"${workspaceRoot}",
				"--editor"
			],
			"cwd": "${workspaceFolder}",
			"console": "internalConsole",
			"stopAtEntry": false
		},
		{
			"name": "Attach to Process",
			"type": "coreclr",
			"request": "attach"
		}
	]
}

This extension C# Tools for Godot did NOT work for me, and you don't need it either. I wouldn't bother installing it.

If you want to see another working vscode launch.json that works, see: https://github.com/chickensoft-games/GodotGame/blob/main/.vscode/launch.json

Note: Using the vscode launch settings debug server and attach modes did not work for me, and weren't necessary either.

4) Put the Exact Full Godot Executable Path into vscode's godot-bin executable location

Head to VSCode settings (Ctrl + ,) and set godot-dotnet-tools.executablePath (or search godot in settings and find Executable Path setting) to the exact path to your executable.

Important: This needs to be exact i.e. It can't be to a wrapper script which launches Godot (this was my original issue). I'm assuming that the vscode extension requires the $0 arg to be the exact full godot exe path, and it uses that path find the debugging symbols too.

The godot-bin is the executable that when you double click, it'll start running godot.

If your using this flatpak, then to get that path run:

❯ flatpak info --show-location org.godotengine.GodotSharp
/home/<YOUR-USER>/.local/share/parallel-launcher/retroarch/app/org.godotengine.GodotSharp/x86_64/stable/<A VERY LONG HASH>

(I have no idea why my path is in parallel-launcher/retroarch lol, I'm also a newbie. Yours could very well be different, but hey ho)

Now open that directory and find the godot-bin. This will probably be in: ./files/bin/godot-bin.

Copy the full path to the godot-bin (with no wildcards - there's no way around this), and paste it into your VSCode godot executable path setting.

5) Prepare .NET Godot for debugging

  • Disable Deploy with Remote Debug (I tried using this setting with debugServer:6006 in VSCode, but that failed)
  • Disable Keep Debug Server Open
  • Enable Godot Debug Adapter Sync Breakpoints Setting (I don't think you have to, but I don't see why not)

6) Run your Godot Game with Breakpoints

Open up any script you want to debug in VSCode, and set a breakpoint somewhere which will definitely run, like a GD.Print("Hello"); in a Ready() function of a scene that gets loaded, then use the 'Launch' configuration.

If everything worked, you should see that it will build your game, and the game will hit your breakpoint:

image

7) Troubleshooting

Here's some telltale signs that show something is wrong. All of the below will not stop on breakpoints:

  • Can't launch VSCode from Godot? Follow the instructions in the README if your using this flatpak: https://github.com/flathub/org.godotengine.GodotSharp#using-an-external-script-editor

  • Your game will skip past the breakpoints, and your GD.Print statement will run and output to the console. Check your godot-bin exe path full and exact.

  • VSCode will cause a 2nd Godot Editor window to open, and may not build or run the game afterwards. Probably a bad launch.json.

  • If breakpoints aren't working and you check the debug console (bottom-right on these images), you'll see far less (yellow on my machine) text upon startup before the game window launches, and no text regarding the loading of .dll/.pdb/symbol files. Check your godot-bin exe path is full and exact.

image

  • VSCode will show a hollow breakpoint and say it couldn't find the debug symbols. Check your godot-bin exe path is full and exact.

  • Note that if you try using the debug server and enable remote debugging, then you won't see this particular symptom. Disable these settings.
    image

  • I didn't need to use Flatseal to change the file permissions for this flatpak I think. But I can't vouch on that.

Final Thoughts

It took me over a month to finally figure out what was going on for me, so I hope that whoever finds this answer, will find this really useful 👍

Also, I found that the instructions for setting up blender in the README were a little unclear. I believe you have to create a new bash script, that contains what the README says. Then set Godot to 3D modeller to use that bash script.

One cool thing I found was: https://github.com/chickensoft-games/GodotGame

If you follow the instructions, it will allow you to setup your godot C# game with everything you need out of the box. I haven't done this yet, but now I got C# debugging working I'll try this next.

Anyways, see you all. Good luck on your .NET Godot journey :D

@hs1955 hs1955 closed this as completed May 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant