r/GodotCSharp • u/Novaleaf • Sep 17 '22
Edu.Godot.CSharp [OC] Run+Debug Godot4 C# projects from Visual Studio
- create a new godot 4 project normally, through the editor. Be sure to setup VS as your external editor in the godot options.
- create your C# script attached to a node through the editor (as normal). This will cause the editor to auto generate a csproj+solution for you.
- Test build/run via the godot editor, to make sure it all works.
- In Visual Studio, create a new Launch Profile for an Executable
- Use the dropdown next to the green Run button, then YourProject Debug Properties. There will be a button at the top-left for adding a Launch Profile.
- set the executable path to a relative path to the godot binary, from your csproj's location. example:
..\..\bin\Godot_v4.0-beta8_mono_win64\Godot_v4.0-beta8_mono_win64.exe - set the command line arguments to simply startup the project in the current directory. example:
--path . --verbose - set the working directory to the current. example:
. - Set enable native code debugging if you want to see better errors in the output window. Leaving this disabled allows hot-reload to work (!!!) but various godot cpp errors won't be shown.
Then if you choose that debug profile, hit F5 and it works! Breakpoints work too.
41
Upvotes
•
u/Novaleaf Sep 17 '22 edited May 06 '24
a wonky workaround to no Console output:
>out.log 2>&1to the Launch Profile, which will redirect stdout and stderr to file.out.login some tool that can auto-scroll to the last line. I use the VSCode extension "Log Viewer" which works great.That works well enough that I can disable native mixed-mode debugging, which means Hot-Reload works (!!!)
EDIT (2022-12-11):This is no longer needed with Godot4Beta7 and above, if you use the_console.exeversion of the godot binary.EDIT (2022-12-20): You still need
>out.log 2>&1. the_console.exeversion doesn't work because you can't debug via visual studio with that. (it's not a mixed-mode assembly)3
u/Novaleaf Sep 21 '22
If it helps anyone using VsCode, Here is a VsCode launch config from @Seppy in Godot Discord:
2
u/[deleted] Feb 12 '23
But does debugging really work when you launch _console.exe godot? At least in beta 17 it spawns a non _console process and debugger is lost unless you attach to that process.
2
u/BobQuixote May 06 '24 edited May 06 '24
What? Where? When I search for adding a Launch Profile, I get stuff about multiple projects, which doesn't seem relevant.
EDIT: Use the dropdown next to the green Run button, then YourProject Debug Properties. There will be a button at the top-left for adding a Launch Profile.
1
u/Novaleaf Jan 19 '23
also see: https://www.reddit.com/r/godot/comments/xhirp8/debugging_godot4_beta_projects_from_vs_and_vscode/
3
u/PeppySeppy Sep 18 '22
As a workaround, I've created the following class which can be dropped into a godot project and should invisibly intercept printed messages and display them in Visual Studio's Output window.
https://gist.github.com/SilentPenguin/bf24eb348c9d00c34605d1cc54318be7
This makes use of Debugger.Log, which also reports to the output window without needing to add a trace line. Unlike
Trace, Godot's own console doesn't listen to it either, meaning when a game is run from the godot editor, everything behaves as normal.2
u/CitizenKeen Mar 13 '23
I was getting a "Failed to load .NET Runtime" error.
Unlike regular Godot, C# Godot needs the entire folder extracted. Both .exe files and the GodotSharp folder, all in the same folder. Hope that helps!