Not working on 4.21.2 macOS. Neither binary vs source nor Xcode vs VS Code helps. Let’s play spot the bug: Engine/Source/Programs/UnrealBuildTool/Configuration/UEBuildTarget.cs
string OutputFilePath = ExecutableBinary.OutputFilePath.FullName;
if (Platform == UnrealTargetPlatform.Mac && OutputFilePath.Contains(".app/Contents/MacOS"))
{
OutputFilePath = OutputFilePath.Substring(0, OutputFilePath.LastIndexOf(".app/Contents/MacOS") + 4);
}
string EnginePath = Utils.CleanDirectorySeparators(UnrealBuildTool.EngineDirectory.MakeRelativeTo(ExecutableBinary.OutputFilePath.Directory), '/');
if (EnginePath.EndsWith("/") == false)
{
EnginePath += "/";
}
GlobalCompileEnvironment.Definitions.Add(String.Format("UE_ENGINE_DIRECTORY=\"{0}\"", EnginePath));
There’s a corner case check for OSX bundles (though in a hacky way, but it’s fine), which strips off Contents/MacOS and assigns it to OutputFilePath. However, OutputFilePath is not accessed again, causing UE_ENGINE_DIRECTORY to be set to relative to the binary’s location in the bundle
- Engine/Source/Runtime/Core/Private/Mac/MacPlatformProcess.cpp sets the working directory to project-root/Binaries/Mac.
- When checking for the EngineDir in Engine/Source/Runtime/Core/Private/GenericPlatform/GenericPlatformMisc.cpp, it will check the default …/…/…/Engine (works fine in fully packaged builds due to some magic), then what UE_ENGINE_DIRECTORY is set to, which is relative to project-root/Binaries/Mac/project.app/Contents/MacOS, not project-root/Binaries/Mac.
Which also means there’s a second bug here: chopping off Contents/MacOS still leaves us a directory higher than what UE_ENGINE_DIRECTORY needs to be set to. Aka UE_ENGINE_DIRECTORY would be relative to project-root/Binaries/Mac/project.app if not for bug #1, but regardless needs to relative to project-root/Binaries/Mac.
The commits, at least on the Release branch, are squashed, but I suspect this is the breaking change:
Change 3378297 on 2017/04/04 by Graeme.Thornton
Fix incorrect generation of UE_ENGINE_DIRECTORY in UBT
Maybe not that fixed. That said, it was likely broken beforehand, and I suspect macOS no-editor debugging has never worked out of the box in UE4. I’ll also note UE4’s “where do I find stuff” logic feels super rickety and is spread out across way too many places and I’m surprised things don’t break constantly for no reason. Then again - maybe they do.
Here’s a possible fixed version, though it needs a bit more testing. Doesn’t break on the ICU data directories, but doesn’t find the cooked content unless I explicitly set it with -Sandbox=“/Saved/Cooked/MacNoEditor” - suspect there’s similar issues with how project dirs are set. If you want to try it, I suggest applying the attached patch file with **git apply filename-of-the-attached.patch ** from the root of a UnrealEngine source checkout. Changed code snippet for reference:
// The hardcoded engine directory needs to be a relative path to match the normal EngineDir format. Not doing so breaks the network file system (TTP#315861).
DirectoryReference EngineDirectory = ExecutableBinary.OutputFilePath.Directory;
if (Platform == UnrealTargetPlatform.Mac && EngineDirectory.FullName.Contains(".app/Contents/MacOS"))
{
EngineDirectory = EngineDirectory.ParentDirectory.ParentDirectory.ParentDirectory;
}
string EnginePath = Utils.CleanDirectorySeparators(UnrealBuildTool.EngineDirectory.MakeRelativeTo(EngineDirectory), '/');
if (EnginePath.EndsWith("/") == false)
{
EnginePath += "/";
}
GlobalCompileEnvironment.Definitions.Add(String.Format("UE_ENGINE_DIRECTORY=\"{0}\"", EnginePath));
Engine/Source/Programs/UnrealBuildTool has a C# Visual Studio project file, compile that (probably on a Windows machine sry) and you should be able to drop the four Engine/Binaries/DotNET/UnrealBuildTool.* files it into the corresponding directory on a macOS UE installation. Note that a normal build of Unreal Engine won’t apply this.
Git patch, might need to rename to file.patch instead of .txt