Adding custom compile flag to build project plugin with installed version

As a precondition to let you know, I am currently working on a installed version of the Unreal 5.2.1 engine.

To add a Blueprint Function Library with my own functions implemented in C++ I have created a small plugin in my project. The code I implemented however requires me to enable exception handling on Windows using the /EHsc flag for the compiler.

To be precise I only have this issue of compiling when I run the “Package project” for Windows in the Unreal 5 editor. The compilation of the C++ class in MSVC opened from the Editor is compiling correctly.

I get the error message:

“error C4530: C++ exception handler used, but unwind semantics are not enabled. Specify /EHsc”
“Error executing C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.34.31933\bin\Hostx64\x64\cl.exe (tool returned code: 2)”

To achieve that I investigated other questions and came along with the solution to add this flag in the VCToolChain.cs file of my UnrealBuilderTool in the installed Unreal 5 engine. However it seems it is not picked up during packaging in the UnrealBuildTool compile step. My change in the VCToolChain.cs is done in the method

“protected virtual void AppendCLArguments_Global(CppCompileEnvironment CompileEnvironment, List Arguments)”

I added there a check if I am in MSVC and then add the flag

if (Target.WindowsPlatform.Compiler.IsMSVC())
{
    // Enable exception handling
    Arguments.Add("/EHsc");
    Arguments.Add("/DPLATFORM_EXCEPTIONS_DISABLED=0");
}

I also found this code part which seems to be also related to exception handling enabling, however I don’t know where I would need to define the condition for the branch to setup /EHsc

// Enable C++ exceptions when building with the editor or when building UHT.
if (CompileEnvironment.bEnableExceptions)
{
    // Enable C++ exception handling, but not C exceptions.
    Arguments.Add("/EHsc");
    Arguments.Add("/DPLATFORM_EXCEPTIONS_DISABLED=0");
}
else
{
    // This is required to disable exception handling in VC platform headers.
    AddDefinition(Arguments, "_HAS_EXCEPTIONS=0");
    Arguments.Add("/DPLATFORM_EXCEPTIONS_DISABLED=1");
}

Does anyone have some hints or ideas on how to resolve this?
Thanks
Thoran

Just modify cs file is not enough, you need ue5 source code to compile into UnrealBuildTool.exe, and copy the file over the same file on ue5 build.

Thanks, for the information. I managed to get it working in the meantime exactly doing what you also proposed, which is effectively rebuilding the tool with the changed *.cs file.
I was initially, wrongly assuming the *.cs file is like a config file that is parsed during runtime, which is not the case.
Thanks again for answering.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.