How can I exclude debug code in shipped build ?

Hello guys,

I would like to ask how can I exclude debug code like GEngine->AddOnScreenDebugMessage() during shipping. I use this kind of debug messages in my project, however I would like to be sure that these will not be displayed in shipped buiild. I prefer some macros because generated code will be cleaner and will not contain conditions and code that will never run.

Thank you

(I wanted to post this to AnswerHub however I get internal error 3 times)

I think you can use:

#ifdef UE_BUILD_DEBUG

Thank you very much, that is what I was looking for.

Also I found my AnswerHub question (for some reason it was created even after internal error).

It is strange but I am not able to get it work. It looks like UE_BUILD_DEBUG is not used in any configuration. I use downloaded binary version and available build configurations are:

DebugGame
DebugGame Editor
Development
Development Editor
Shipping

I use DebugGame Editor for debugging and UE_BUILD_DEBUG is always 0.
I think this is similar issue: Are there #defines for conditional compilation based on the build configurations? - Programming & Scripting - Epic Developer Community Forums

EDIT: I think I found reason: How can I differentiate between Macros for DebugGame Editor vs Development Editor? - Debugging, Optimization, & Profiling - Epic Developer Community Forums. It looks like I will need to make custom macro for DebugGame Editor.

This will cause compilation errors. Use #if UE_BUILD_DEBUG instead. The reason is that #ifdef returns true for #define UE_BUILD_DEBUG 0, since it is defined, just to the value zero.

In general, at Epic we use #if !UE_BUILD_SHIPPING (not shipping).

2 Likes

There are some useful macros that can come in handy many times like:

#if UE_BUILD_TEST
#if UE_BUILD_DEVELOPMENT
#if UE_BUILD_DEBUG
#if UE_BUILD_DEBUGGAME

among others.

Cheers,
Moss

4 Likes