Check UE4 Version at compile time C#

ModuleRules had a change to the constructor in 4.16, so I find I have to manually comment out lines for my modules.

Plugins\ChromaSDKPlugin\Source\ChromaSDKPlugin\ChromaSDKPlugin.Build.cs

using UnrealBuildTool;

public class ChromaSDKPlugin : ModuleRules
{
	public ChromaSDKPlugin(TargetInfo Target) //4.15 or lower
	//public ChromaSDKPlugin(ReadOnlyTargetRules Target) : base(Target) // 4.16 or better

Since this is inheritance, it’s something that has to be determined at compile time. Is there a macro or preprocessor directive that can detect the engine version? That way the plugin can support both versions without adjusting the comments?

In the meantime I’ll have documentation to adjust the comments.

Thanks!

~TimG

Here’s one workaround.

#if WITH_FORWARDED_MODULE_RULES_CTOR
    public ChromaSDKPlugin(ReadOnlyTargetRules Target) : base(Target) // 4.16 or better
#else
    public ChromaSDKPlugin(TargetInfo Target) //4.15 or lower
#endif

4.17 and later define the UE_4_XX_OR_LATER preprocessor definition, where XX is e.g. 17, 18, 19.

1 Like