Hello. I’d like to help anyone still experiencing this issue, resolve the build error. I’ll be giving two point of views in a project I’ve been working on. The first is a plugin for MySQL, and the second is MyProject.Build.cs.
MySQL Plugin Build.cs file [UE4.15 to 16]
using System.IO;
namespace UnrealBuildTool.Rules
{
using System.IO;
public class MySQL : ModuleRules
{
public MySQL(TargetRules Target)
{
PublicIncludePaths.AddRange(
new string[] {
"MySQL/Public",
"MySQL/Classes"
// ... add public include paths required here ...
}
);
PrivateIncludePaths.AddRange(
new string[] {
"MySQL/Private",
// ... add other private include paths required here ...
}
);
PublicDependencyModuleNames.AddRange(
new string[]
{
"Core",
"CoreUObject",
"Engine"
// ... add other public dependencies that you statically link with here ...
}
);
PrivateDependencyModuleNames.AddRange(
new string[]
{
"CoreUObject",
"Engine",
"Slate",
"SlateCore"
// ... add private dependencies that you statically link with here ...
}
);
DynamicallyLoadedModuleNames.AddRange(
new string[]
{
// ... add any modules that your module loads dynamically here ...
}
);
UEBuildConfiguration.bForceEnableExceptions = true;
}
}
}
There are a few lines that you have to focus on to correct this issue. The first is, Unreal Engine now uses class type ReadOnlyTargetRules in the constructor. The constructor must also inherit from base class Target, : base(Target) like so. Another thing to focus on, which may be irrelevant in your case, but caused me issues for my project; since TargetRules is now ReadOnly, you must remove any lines that try to change a value of Target.
Here’s an example of what I mean:
public MySQL(TargetRules Target)
{...}
must now be changed to:
public MySQL(ReadOnlyTargetRules Target) : base(Target)
{...}
If you were assigning any values to target, you must remove those as well (I used Target to force enable exceptions):
UEBuildConfiguration.bForceEnableExceptions = true;
This must be removed or commented out as such:
// Can no longer use in 4.16 as TargetRules data type has been changed to a new data type called ReadOnlyTargetRules!
//UEBuildConfiguration.bForceEnableExceptions = true;
in order to compile to 4.16.
MyProject.Build.cs [UE4.15 to 16]
The same goes for your project’s build file as well.
public class MyProject : ModuleRules
{
public MyProject(TargetRules Target)
{...}
}
must be changed to:
public class Defcon5Dev : ModuleRules
{
public Defcon5Dev(ReadOnlyTargetRules Target)
{...}
}
I didn’t have to inherit from base(Target) that time, but I’m not certain if that is a must or not for the Project.Build.cs file.