In Unreal Engine we have such things as #if WITH_EDITOR how it called? and what else we…
- User
In Unreal Engine we have such things as #if WITH_EDITOR how it called? and what else we have
- Assistant
In Unreal Engine we have such things as #if WITH_EDITOR how it called? and what else we have
In Unreal Engine, macros like #if WITH_EDITOR are preprocessor directives used for conditional compilation. These macros allow developers to include or exclude blocks of code based on various conditions such as build configuration, platform, or specific features. This mechanism helps in optimizing the game for different environments (e.g., editor vs. runtime) and managing platform-specific code.
Build Configuration Macros:
UE_BUILD_DEBUG: Compiled in Debug builds.UE_BUILD_DEVELOPMENT: Compiled in Development builds.UE_BUILD_TEST: Compiled in Test builds.UE_BUILD_SHIPPING: Compiled in Shipping builds.#if UE_BUILD_DEBUG
// Debug-specific code
#endif
Platform-Specific Macros:
PLATFORM_WINDOWSPLATFORM_MACPLATFORM_LINUXPLATFORM_IOSPLATFORM_ANDROID#if PLATFORM_WINDOWS
// Windows-specific code
#elif PLATFORM_MAC
// macOS-specific code
#endif
Editor vs. Runtime Macros:
WITH_EDITOR: Code within this block is only compiled when building the editor.UE_EDITOR: Similar to WITH_EDITOR, used in some contexts.#if WITH_EDITOR
// Editor-only code
#endif
Feature-Specific Macros:
WITH_PHYSX: Compiled if PhysX support is included.WITH_CHAOS: Compiled if Chaos physics is enabled.WITH_AUTOMATION_TESTS: Includes automation testing code.WITH_EDITORONLY_DATA: Includes data only necessary for the editor.#if WITH_AUTOMATION_TESTS
// Automation test code
#endif
Optimization and Debugging Macros:
DO_CHECK: Used for additional runtime checks in debug builds.DO_GUARD_SLOW: Similar to DO_CHECK but for slower, more comprehensive guards.#if DO_CHECK
// Runtime checks
#endif
Engine Feature Toggles:
UE_ENABLE_ICU: Enables or disables International Components for Unicode.UE_WITH_PARTIO: Controls inclusion of the Partio library for particle simulations.#if UE_ENABLE_ICU
// ICU-related code
#endif
Example 1: Editor-Only Functionality
#if WITH_EDITOR
void AMyActor::EditorOnlyFunction()
{
// This function will only exist in editor builds
}
#endif
Example 2: Platform-Specific Code
void AMyActor::PlatformSpecificFunction()
{
#if PLATFORM_WINDOWS
// Windows-specific implementation
#elif PLATFORM_MAC
// macOS-specific implementation
#else
// Other platforms
#endif
}
Example 3: Conditional Logging Based on Build Configuration
void AMyActor::LogDebugInfo()
{
#if UE_BUILD_DEBUG
UE_LOG(LogTemp, Warning, TEXT("Debug build: Detailed info."));
#elif UE_BUILD_SHIPPING
// No logging in shipping builds
#endif
}
By leveraging these preprocessor macros effectively, you can create flexible, optimized, and maintainable code tailored to various build configurations and target platforms within Unreal Engine.
Not yet included in a published release.