How can I differentiate between Macros for DebugGame Editor vs Development Editor?

I’m trying to detect when DebugGame Editor vs Development Editor is selected as a configuration target, but it looks like UBT does not actually define any macros based on the configuration… The UBT defines come from however the UE4 engine was compiled not the actual game project.

Is there some way for me to do an #if DEBUG_GAME or #if DEVELOPMENT compile time switch?

Thanks

Hey there, if you want a compile time flag, try one of UE_BUILD_DEBUG or UE_BUILD_DEVELOPMENT.

You can see this is how FApp::GetBuildConfiguration() returns an EBuildConfigurations::Type.

HI Andrew,

UE_BUILD_DEVELOPMENT is the only flag set in a game project no matter what build configuration is selected (I’m not building the UE4 engine, just a game project).

FApp::GetBuildConfiguration() is a runtime check not useful for configuring linkages or other stuff you want stripped out of a non-debug build for example.

I’ve been able to check the Target.Configuration in the Build.cs to add my own defines, but I think there should be some new UE_BUILD_ flag for a game project that is set by the build system depending on the confguration.

When building in DebugGame, the engine is built with development settings - it’s only your game modules that are built with debug. This will explain why the macro is set to development.

To clarify:

Debug = Engine Modules in Debug + Game Modules in Debug
Debug Game = Engine Module in Development + Game Modules in Debug

I think you have 2 options here: build in Debug not DebugGame, or define your own debug symbols for the game modules.

I think you can override the environment like so:

public override void SetupGlobalEnvironment(
    TargetInfo Target,
    ref LinkEnvironmentConfiguration OutLinkEnvironmentConfiguration,
    ref CPPEnvironmentConfiguration OutCPPEnvironmentConfiguration
    )
{
    // Enable NaN tracking during development
    if (Target.Configuration != UnrealTargetConfiguration.DebugGame)
    {
       OutCPPEnvironmentConfiguration.Definitions.Add("GAME_DEBUG=1");
    }
}

in your target.cs file.

Awesome Andrew thanks. I was able to come up with something identical except I’m doing it in the constructor of my ModuleRules. I’ll mark your answer as accepted since that’s really useful to have handy.

Thanks for your help. UE4 is world class and a pleasure to work with!

Answered:

When building in DebugGame, the engine is built with development settings - it’s only your game modules that are built with debug. This will explain why the macro is set to development.

To clarify:

Debug = Engine Modules in Debug + Game Modules in Debug Debug Game = Engine Module in Development + Game Modules in Debug

I think you have 2 options here: build in Debug not DebugGame, or define your own debug symbols for the game modules.

I think you can override the environment like so:

public override void SetupGlobalEnvironment(
TargetInfo Target,
ref LinkEnvironmentConfiguration OutLinkEnvironmentConfiguration,
ref CPPEnvironmentConfiguration OutCPPEnvironmentConfiguration
)
{
// Enable NaN tracking during development
if (Target.Configuration != UnrealTargetConfiguration.DebugGame)
{
OutCPPEnvironmentConfiguration.Definitions.Add(“GAME_DEBUG=1”);
}
}
in your target.cs file.

I found the solution for latest UE4 version, define your macros in the constructor of MyProject.Build.cs ,like this:

public class MyProj : ModuleRules  
{  
    public MyProj(TargetInfo Target)  
    {  
        PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore", "UMG", "Slate", "SlateCore" });  
        PrivateDependencyModuleNames.AddRange(new string[] {  });  
  
  
        Definitions.Add("_CRT_SECURE_NO_WARNINGS");  
    }  
}  

also can see example here:

https://github.com/monsieurgustav/UE4-OSC/blob/master/OSC/Source/OSC/OSC.Build.cs

if (Target.Type.HasValue && TargetRules.IsEditorType(Target.Type.Value))
{
PrivateDependencyModuleNames.Add(“UnrealEd”);
}

What about UE_BUILD_DEVELOPMENT_WITH_DEBUGGAME? I found it in /Intermediate/Build/Win64/UE4Editor/[Build type]/MyGame/PCH.MyGame.h, and seems to be set to 1 when debugging just the game. Not sure how the macros there are related to those in /Runtime/Core/Public/Misc/Build.h (which contains UE_BUILD_[DEBUG/TEST/DEVELOPMENT/SHIPPING].