LayerNames error bricking my Mac projects

After updating to latest Xcode and MacOS, then doing landscape work, I’m getting the following error:

variable “LayerNames” set but not used [-Werror,-Wunused-but-set-variable]

I can’t even open my projects anymore. Has anyone else seen this before?


I also see this error

In file included from /src/ActionRoguelike/Intermediate/Build/Mac/x86_64/ActionRoguelikeEditor/Development/Engine/SharedPCH.Engine.ShadowErrors.h:284:
In file included from /Users/Shared/Epic Games/UE_4.27/Engine/Source/Runtime/Engine/Public/EngineSharedPCH.h:572:
0>/Users/Shared/Epic Games/UE_4.27/Engine/Source/Runtime/Engine/Classes/Materials/Material.h:272:2: Error  : C++ requires a type specifier for all declarations
0>/Users/Shared/Epic Games/UE_4.27/Engine/Source/Runtime/CoreUObject/Public/UObject/ObjectMacros.h:630:37: Reference  : expanded from macro 'GENERATED_USTRUCT_BODY'

I’m also seeing this issue as of updating XCode. The error is in Material.h line 1281.

I’m on UE4 4.27.2

Here’s the version of XCode I updated to:

1 Like

I’m getting that same error. All my c++ projects are broken and it will fail to compile any c++ project. Blueprint projects however work… But that’s not good enough. Freakin LayerNames

downloaded and replaced Xcode 13.3 with Xcode 13.2.1 and everything works fine again

Yea that works! Thanks u

1 Like

If you’re logged into an Apple developer account, here’s a direct link:

I work fine for Xcode 13.3 by adding following lines to .target.cs file in my project:

bOverrideBuildEnvironment = true;
AdditionalCompilerArguments = "-Wno-unused-but-set-variable";

It worked! Thanks!

Thanks, this worked, though I also had to add those two lines to my Editor.Target.cs file as well.

Thank you so much for this! It worked! For me, this code needed to be added to Target.cs and Editor.Target.cs through xcode.

1 Like

Thanks very much! It worked

Hi. Where should I add those lines in that C# file?

1 Like

Those files are in following path in your project:


Thanks :slight_smile:

any chance you could educate us on what these lines mean and how you knew where to put them?

I suggest you look up C++ compiler flags

To solve this issue, here is the proper fix.

Open your <project_name>Editor.Build.cs and override your compiler instructor to ignore the warning like this:

Copy the following two lines to your <project_name>Editor.Build.cs

bOverrideBuildEnvironment = true;
AdditionalCompilerArguments = "-Wno-unused-but-set-variable";

Do not add these lines to Build.cs, you just need to override the Editor.Build.cs

Bam! Solved


In UE source code, you can also change the project’s BuildSeting->Other C Flags and add “-Wno-unused-but-set-variable”.


If anyone is still trying to figure this out I have been trying to fix this a little over the past few weeks and yesterday I spent a few hours trying to figure it out until me in my coder-rage state decided to add the lines in the screenshot to “Material.h” in the Xcode files of the Ue4 engine.

Originally the constant was named “ScrewXcode,” but I changed it because I didn’t want my app to run into some Xcode loving developer checking my code and risk insulting them. This instantly fixed my problem and I am using Xcode 13.4.1 and Unreal Engine 4.27.2

Find “Material.h” (File path is "Engine(Was shown for me outside of my project, above it in the sidebar)>UE4>Source>Runtime>Engine>Classes>Materials>Material.h(For me it was the top file in the Materials folder)

Screenshot of where Engine folder is:
Screen Shot 2022-07-04 at 12.40.29 PM

Once you find Material.h, go to line 1279, that’s where the error was for me, but if that’s not where it is for you, go to the error. Then make a new line right below the line with “const TArray* LayerNames = &LayersExpression->GetLayerNames();” and add something like this to that new line below LayerNames. Example: “const TArray* XcodeAreYouHappyNow = LayerNames;”

Also Xcode might ask you to unlock “Material.h,” unlock it so you can edit it.

Hopefully this solves the problem for anyone who is still struggling.