Why #if DEBUG is still true in exported program?

Godot Version

4.4.1 - mono

Question

For example:

#if DEBUG
    private const float TestValue = 0f;
#else
    private const float TestValue = 45f;
#endif

TestValue will still be 0 even the project exported.

I’ve closed debug symbles and set debug/export_console_wrapper to false in Windows export config but useless. I’ve also set C# project property config to ExportRelease which excludes DEBUG constant but useless, too.

Is there any way to use #if DEBUG properly in Godot mono?

1 Like

OS.IsDebugBuild() should do the trick, although someone more experienced with C# might want to chime in regarding the preprocessor directive approach.

In the very last window of the export process (the one where you choose where you want to save the exported files), there is a checkbox above the Save and Cancel buttons. That’s where you can switch between exporting a debug and a release build. Unchecking it will give you a build with DEBUG undefined. The other options you mentioned aren’t useless, they control other things. Export Console Wrapper conditions the export of the additional .console.exe file, and Include Debug Symbols conditions the inclusion of actual debug symbols in the produced files.

3 Likes

Cool, it works. I didn’t expect to switch debug and release build here, especially “With Debug” makes me a misunderstanding of a release build with some debug symbols. I prefer they move this switch into export settings config.

Thank you a lot.

Thanks for reply. Preprocessor is convenient when class property definition meats different condition. OS.IsDebugBuild() seems more likely to use in function body other than class property definition.