Preprocessor Directives in Unreal Engine 5
UE5 has some great preprocessor directives already established in the code base we can leverage.

Game Engine
Unreal Engine 5.5.3
IDE
Rider 2024.3.6
Project Name
MyProject
OS
macOS Sequoia 15.3.1
Preprocessor directives are very helpful when programming to determine logic before compile time. Unreal Engine 5 is a very large code base and it provides a lot of established preprocessor directives to assist with its multifaceted responsibilities.
When making new actors in UE5 via C++ I like adding a default scene component as the root similar to when a new actor is created in editor. Additionally I like setting the bVisualizeComponent
variable to true
so I can see it in the editor.
MySceneComp = CreateDefaultSubobject<USceneComponent>(TEXT("MySceneComp"));
MySceneComp->bVisualizeComponent = true;
However, when setting bVisualizeComponent
to true
, the project will fail to build. So with that I wrap the statement in a preprocess directive so I can visualize the component while also being able to package the project. I use WITH_EDITORONLY_DATA
to limit the visualization feature to only trigger when working in the editor.
MySceneComp = CreateDefaultSubobject<USceneComponent>(TEXT("MySceneComp"));
#if WITH_EDITORONLY_DATA
MySceneComp->bVisualizeComponent = true;
#endif
There are plenty of helpful preprocessor directives available. Below is a list of some that I've come across that might be handy in the future.
Editor Preprocessor Directives
- #if WITH_EDITOR
- #if WITH_EDITORDATA_ONLY
Build Preprocessor Directives
- #if UE_BUILD_DEBUG
- #if UE_BUILD_DEVELOPMENT
- #if UE_BUILD_SHIPPING
- #if UE_BUILD_TEST
Build Preprocessor Directives
- #if PLATFORM_32BITS
- #if PLATFORM_64BITS
- #if PLATFORM_ANDROID
- #if PLATFORM_IOS
- #if PLATFORM_LINUX
- #if PLATFORM_MAC
- #if PLATFORM_WINDOWS
I look forward to using more preprocessor directives in the future.