Unreal won't compile my project on MacOS

Hello everyone,

I tried resolving this problem for hours on end now, but I can’t.
Every time I try to open a project in unreal engine it says “This project could not be compiled. Would you like it to open it in Visual Studio Code?”

I currently run on MacOS 12.3 Monterey, 8GB of ram, and an Apple M1 chip if it matters.
My currently version of Unreal is 4.27.2, and the latest xCode version 13.3.

Until now I tried another version of Unreal (4.25), I tried changing project path, removing spaces, removing some characters that I thought were sketchy, I reinstalled all of them (Epic Games, Unreal, xCode and VS code) and still nothing. It won’t let me import a project, for example Bull&Cows from your course, or not even create a new one from scratch.

Here is the error details:

The project could not be compiled. Would you like to open it in Visual Studio Code?


Running Mono...

Found mono via known Mono.framework path
Running system mono/msbuild, version: Mono JIT compiler version 6.12.0.140 (2020-02/51d876a041e Thu Apr 29 10:44:55 EDT 2021)
/Users/Shared/Epic Games/UE_4.27/Engine /Users/Shared/Epic Games/UE_4.27/Engine/Binaries/Mac
Creating makefile for BuildingEscapeEditor (no existing makefile)
@progress push 5%
Parsing headers for BuildingEscapeEditor
  Running UnrealHeaderTool "/Users/denis/Documents/Unreal Projects/BuildingEscape/BuildingEscape.uproject" "/Users/denis/Documents/Unreal Projects/BuildingEscape/Intermediate/Build/Mac/x86_64/BuildingEscapeEditor/Development/BuildingEscapeEditor.uhtmanifest" -LogCmds="loginit warning, logexit warning, logdatabase error" -Unattended -WarningsAsErrors -abslog="/Users/denis/Library/Application Support/Epic/UnrealBuildTool/Log_UHT.txt" -installed
2022-03-24 14:19:39.290 UnrealHeaderTool[13827:65740] [UE4] Looking for binary: ../../../Engine/Programs/UnrealHeaderTool/Config/BinaryConfig.ini
LogInit: Display: Loading text-based GConfig....
Reflection code generated for BuildingEscapeEditor in 6.4580576 seconds
@progress pop
Building BuildingEscapeEditor...
Performing 7 actions (5 in parallel)
[1/7] Compile SharedPCH.Engine.ShadowErrors.h
In file included from /Users/denis/Documents/Unreal Projects/BuildingEscape/Intermediate/Build/Mac/x86_64/BuildingEscapeEditor/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:
/Users/Shared/Epic Games/UE_4.27/Engine/Source/Runtime/Engine/Classes/Materials/Material.h:1279:26: error: variable 'LayerNames' set but not used [-Werror,-Wunused-but-set-variable]
                                const TArray<FText>* LayerNames = &LayersExpression->GetLayerNames();
                                                     ^
1 error generated.


EDIT: Out of desperation, I proceeded to comment line 1279 in Material.h, and couple lines below that there was another one that used that variable so i commented that too. To my surprise it worked… but I don’t think that’s the right fix at all, so I’m still open to suggestions/help

You have to add some flags to MacToolChain.cs. See my diff below.

diff --git a/Engine/Source/Programs/UnrealBuildTool/Platform/Mac/MacToolChain.cs b/Engine/Source/Programs/UnrealBuildTool/Platform/Mac/MacToolChain.cs
index 32094cfa3..31b0ae9c7 100644
--- a/Engine/Source/Programs/UnrealBuildTool/Platform/Mac/MacToolChain.cs
+++ b/Engine/Source/Programs/UnrealBuildTool/Platform/Mac/MacToolChain.cs
@@ -237,6 +237,19 @@ namespace UnrealBuildTool
 				Result += " -Wundef" + (CompileEnvironment.bUndefinedIdentifierWarningsAsErrors ? "" : " -Wno-error=undef");
 			}
 
+			// https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html
+			Result += " -Wno-deprecated";
+			Result += " -Wno-deprecated-declarations";
+			Result += " -Wno-int-to-void-pointer-cast";
+			Result += " -Wno-non-literal-null-conversion";
+			Result += " -Wno-overloaded-virtual";
+			Result += " -Wno-pointer-to-int-cast";
+			Result += " -Wno-pragma-once-outside-header";
+			Result += " -Wno-unused-but-set-variable";
+			Result += " -Wno-unused-function";
+			Result += " -Wno-unused-result";
+			Result += " -Wno-unused-variable";
+
 			Result += " -c";
 
 			// Pass through architecture and OS info

I didn’t try that out yet, for now apparently an xCode downgrade to 13.2.1 solved it. If in the future I’m gonna be forced to update xCode I might try it.

Thank you very much.

Hi I am running into this same issue and modifying MacToolChain.cs as recommended by @douglaslassance is not doing the trick for me:

I still get the same error:

 /Users/Shared/Epic Games/UE_4.27/Engine/Source/Runtime/Engine/Classes/Materials/Material.h:1279:26: 
error: variable 'LayerNames'  set but not used [-Werror,-Wunused-but-set-variable]
const TArray<FText>* LayerNames = &Layers Expression->GetLayerNames();

Any ideas anything else I could do beyond downgrading my Xcode?

Thanks,
Mariano

Are you sure you added that in the right place?

Just to explain things:
The warning being emitted is Wunused-but-set-variable and adding no- after ‘W’ means to not emit that warning and -Werror means to treat warnings as errors.

@Mariano_Lizarraga You can just delete those lines as well as the surrounding WITH_EDITOR macro. Whoever left those lines in that file was probably using them for some editor debugging and forgot to delete them before committing their changes to the main branch. That function has been refactored a bit in UE5 and those lines have been removed.

Also, treating warnings as errors isn’t necessarily a bad thing. In fact, ignored warnings can start to pile up (especially on larger projects) which can lead to bugs at runtime that are difficult to track down. It’s also good to keep warnings down to a minimum (ideally zero) in UE4 because often times you’ll want to log your own warnings for debugging purposes and it can be hard to spot them in the log if they are buried among several other unrelated warnings. There are various methods for filtering log messages of course, but then you might apply a filter and forget about it later which leaves you wondering why you aren’t getting certain log messages (speaking from experience here :sweat_smile:).

Thanks @DanM and @SteveMerritt for your prompt replies.

I am familiar with the compiler flags (but nuclear how these get pulled by the compilation process in Unreal).

Just in case anyone stumbles into this post – I ended up downgrading Xcode to solve this error.

As a side note, I still don’t quite grasp how changing compiler version (specially a minor release, I went from 13.3.1 to 13.2.1) would suddenly make compiler flags like -WarningsAsErrors no longer relevant. I guess I’ll better understand as I progress through the course.

Thanks for all the help!
Mariano

That’s not what happened. -Werror is still applied but -Wunused-but-set-variable didn’t exist in Xcode 13.2. According to this table Xcode 13.2 is using LLVM 12 and 13.3 is using 13

Here’s the output from Clang 12 and 13 with that flag
Compiler Explorer

Thanks @DanM for clarifying this and helping me understand the details! This is very helpful.

1 Like

In case you don’t have to stick with 4.27, I just wanted to let you know that it’s been a smoother ride with Unreal 5.0.0.

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

Privacy & Terms