现象
Visual Studio 编译 UE 项目失败,无任何错误日志输出,手动运行编译命令输出:
...
Using 'git status' to determine working set for adaptive non-unity build (D:\Code\Unreal Projects\ShowreelOne).
Creating makefile for ShowreelOneEditor (no existing makefile)至此直接退出,无报错、无任何其他输出。
检查 UnrealBuildTool\Log.txt 发现日志突然“腰斩”,没有任何实质性的错误堆栈输出。
排查
如此看来像是 dotnet (UnrealBuildTool) 遇到错误直接闪退,转向检查 Windows 系统日志。
进入 Windows 日志 -> 应用程序,找到对应时间的 dotnet.exe 崩溃记录:
Application: dotnet.exe
CoreCLR Version: 8.0.1825.31117
.NET Version: 8.0.18
Description: The process was terminated due to an unhandled exception.
Exception Info: System.ArgumentException: Path fragment '"Content/Ocean/\345\215\240\344\275\215RTArray.uasset"' contains invalid directory separators.
at EpicGames.Core.FileSystemReference.CombineStrings(DirectoryReference baseDirectory, String[] fragments)
at UnrealBuildTool.GitSourceFileWorkingSet.AddPath(String Path)
at UnrealBuildTool.GitSourceFileWorkingSet.OutputDataReceived(Object Sender, DataReceivedEventArgs Args)
at System.Diagnostics.AsyncStreamReader.FlushMessageQueue(Boolean rethrowInNewThread)
--- End of stack trace from previous location ---
at System.Threading.ThreadPoolWorkQueue.Dispatch()
at System.Threading.PortableThreadPool.WorkerThread.WorkerThreadStart()原因分析
这是一场由 UnrealBuildTool 和 Git 配合引发的崩溃:
- UnrealBuildTool 机制: 虚幻引擎的 UnrealBuildTool 为了加速编译,会在后台静默运行
git status来获取工作区变动。 - Git 的默认转义: 当项目中存在中文命名的资产(如
占位RTArray.uasset)时,Git 默认会将非 ASCII 字符转义为带反斜杠和双引号的八进制乱码(即\345\215...)。 - 解析崩溃: UBT 读取到这串乱码后,其路径解析器无法处理这些意外的反斜杠和双引号,直接抛出异常并导致进程瞬间死亡,连写日志的时间都没有。
解决方案
修改 Git 配置 让 Git 停止对中文路径进行八进制转义:
git config --global core.quotepath false提示
在实际工程中还是尽量避免使用中文,引擎底层的很多 C++ 模块和第三方库对 UTF-8 或中文字符的支持非常脆弱。