Get UE version in ModuleRules (.Build.cs file)

In 4.17 Epic introduced C# preprocessor macros for this (see release notes), and you can now conditionally compile blocks with something like:

#if UE_4_17_OR_LATER
// Do something
#else
// Do something else
#endif

Additionally, from 4.16 the macro WITH_FORWARDED_MODULE_RULES_CTOR is also defined. This was intended to decide whether the constructor of your ModuleRules subclass should receive a TargetInfo (up to 4.15) or a ReadOnlyTargetRules (from 4.16). However, you could use it to check for version 4.16 or later too (assuming that macro will not go away in the future…); that is, you could do:

#if WITH_FORWARDED_MODULE_RULES_CTOR
#define UE_4_16_OR_LATER
#endf
1 Like