Skip to main content

Compiler Flags

How to pass compiler flags such as /Zc:nrvo- to the Unreal build process.

Visual Studio debugger can't see C structs if they are returned in a function

This has been raised as a bug in the MSVC compiler here and as at September 2025 there is no fix.

When debugging a function which returns a struct created in that function, like this:

FSavitskyResult Savitsky2(const FSavitskyInput& In)
{
FSavitskyResult Out;
Out.Lift = ...
return Out;
}

the compiler won't show you the members of the struct, instead you see this error message:

There is more discussion of the cause of this problem here and here

The workaround is to pass the flag /Zc:nrvo- on the compiler line.

To do this add this to the project [ProjectName]EditorTarget.cs file:

if (Target.Configuration == UnrealTargetConfiguration.Debug || 
Target.Configuration == UnrealTargetConfiguration.DebugGame)
{
bOverrideBuildEnvironment = true;
AdditionalCompilerArguments += "/Zc:nrvo-";
}

Once you have made this change and recompiled the project you should be able to see the members of the struct:

Building from Source

If you have a project with this:

bOverrideBuildEnvironment = true;
AdditionalCompilerArguments += "/Zc:nrvo-";

and you change it to build using the engine source, when you make a change to your code the whole engine will rebuild.

In the build log file D:\EpicSource\release\Engine\Programs\UnrealBuildTool\Log.txt you will see something like this:

Found 5 shared PCH headers (listed in order of preference):
UnrealEd
Engine
Slate
CoreUObject
Core
Updating D:\EpicSource\release\Engine\Intermediate\Build\Win64\x64\UnrealEditor\Debug\Core\SharedPCH.Core.Cpp20.h.obj.rsp: contents have changed. Saving previous version to
D:\EpicSource\release\Engine\Intermediate\Build\Win64\x64\UnrealEditor\Debug\Core\SharedPCH.Core.Cpp20.h.obj.rsp.old.

The file D:\EpicSource\release\Engine\Intermediate\Build\Win64\x64\UnrealEditor\Debug\Core\SharedPCH.Core.Cpp20.h.obj.rsp is a response file, which is used to pass arguments to Visual Studio when a command line would be too long. The difference between SharedPCH.Core.Cpp20.h.obj.rsp and SharedPCH.Core.Cpp20.h.obj.rsp.old is this line:

/Zc:nrvo-

I think what happens is when you do the first compile, the response file is created, then engine source is compiled, then your project is compiled. When your project is compiled the build system sees the AdditionalCompilerArguments += "/Zc:nrvo-", thinks it applies to the engine build and updates the response file. Next time you do a build, the build process sees the response file has changed and does a complete rebuild.

Fix #1 - Using a Unique Build Environment

This means changing:

if (Target.Configuration == UnrealTargetConfiguration.Debug || 
Target.Configuration == UnrealTargetConfiguration.DebugGame)
{
bOverrideBuildEnvironment = true;
AdditionalCompilerArguments += "/Zc:nrvo-";
}

to:

if (Target.Configuration == UnrealTargetConfiguration.Debug || 
Target.Configuration == UnrealTargetConfiguration.DebugGame)
{
BuildEnvironment = TargetBuildEnvironment.Unique;
AdditionalCompilerArguments += "/Zc:nrvo-";
}

Instead of building the engine inside the engine source directory, the engine is compiled into directories under your own project. So, the response file which was at
> [SourceInstallDir]\Engine\Intermediate\Build\Win64\x64\UnrealEditor\Debug\Core\SharedPCH.Core.Cpp20.h.obj.rsp
is now at
> [YourProject]\Intermediate\Build\Win64\x64[ProjectName]\Debug\Core\SharedPCH.Core.Cpp20.h.obj.rsp

and it does have the /Zc:nrvo- option specified in it.

This approach takes approximately 100 GB of disk space.

Making a change to a file in your project does not cause an engine rebuild so this approach works.

Fix #2 - Turning off PCH files

Turn off PCH in your project like this:

if (Target.Configuration == UnrealTargetConfiguration.Debug || Target.Configuration == UnrealTargetConfiguration.DebugGame)
{
bUsePCHFiles = false;
bOverrideBuildEnvironment = true;
AdditionalCompilerArguments += "/Zc:nrvo-";
}

In theory the engine source will compile with shared precompiled headers but your code will not, so the response file will never be updated with the /Zc:nrvo- option

This compiles 3244 files, then 7819 files.

When attempting to run the project it rebuilds with this message:

1>Invalidating makefile for ... (Module.Launch.cpp.obj.rsp modified)

So, this approach does not work.

Fix #3 - Disabling AdditionalCompilerArguments for Source Builds

Depending on why you added additional arguments, this may be appropriate. In [Project].Target.cs you can check so see if the build is a source build (bIsEngineInstalled will be false) and only if it is not a source build then use AdditionalCompilerArguments.

if ( bIsEngineInstalled )
{
if (Target.Configuration == UnrealTargetConfiguration.Debug ||
Target.Configuration == UnrealTargetConfiguration.DebugGame)
{
bOverrideBuildEnvironment = true;
AdditionalCompilerArguments += "/Zc:nrvo-";
}
}

References

Build Tool Target Reference