前言
准备200GB的磁盘空间
VS 2019 (Default)
备注:由于本人使用的是5.1版本源码,实际上应该采用VS 2022编译器(官网推荐指定的),导致了下面的很多问题,因此,安装VS2022是最佳的选择
VS设置参考
设置虚幻引擎的Visual Studio | 虚幻引擎文档 (unrealengine.com)
1注册Epic
2注册github
3关联账号
在UE官网登入账号并且关联github账号
4下载源码
git clone https://github.com/EpicGames/UnrealEngine.git
下载代码
git branch --all
查看所有版本
git checkout remotes/origin/5.1
切换到5.1版本
问题
Administrator@DESKTOP-NIH84A7 MINGW64 /f/dongshenghua/ue5.0
$ git clone https://github.com/EpicGames/UnrealEngine.git
Cloning into 'UnrealEngine'...
fatal: protocol ' https' is not supported
解决方案
账号登陆GITHUB网址,然后输入网址,重新定位下引擎库
然后重新执行
EpicGames/UnrealEngine: Unreal Engine source code (github.com)
5 执行Setup.bat
顺利的话,完全执行以后,会自动退出
5.1 执行出错提示Failed to download
Failed to download 'http://cdn.unrealengine.com/dependencies/UnrealEngine-24819931/19acf26186763763ae43ec3e4bd12b5a50105e41': SocketException: 远程主机强迫关闭了一个现有的连接。
Wrapped by IOException: Unable to read data from the transport connection: 远程主机强迫关闭了一个现有的连接。.
at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.ThrowException(SocketError error, CancellationToken cancellationToken)
at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.System.Threading.Tasks.Sources.IValueTaskSource<System.Int32>.GetResult(Int16 token)
at System.Net.Http.HttpConnection.InitialFillAsync(Boolean async)
at System.Net.Http.HttpConnection.SendAsyncCore(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)Wrapped by HttpRequestException: An error occurred while sending the request.
at System.Net.Http.HttpConnection.SendAsyncCore(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
at System.Net.Http.HttpConnectionPool.SendWithVersionDetectionAndRetryAsync(HttpRequestMessage request, Boolean async, Boolean doRequestAuth, CancellationToken cancellationToken)
at System.Net.Http.RedirectHandler.SendAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
at System.Net.Http.HttpClient.<SendAsync>g__Core|83_0(HttpRequestMessage request, HttpCompletionOption completionOption, CancellationTokenSource cts, Boolean disposeCts, CancellationTokenSource pendingRequestsCts, CancellationToken originalCancellationToken)
at GitDependencies.Program.DownloadAndExtractFiles(String Url, Uri Proxy, String CacheFileName, Int64 CompressedSize, String ExpectedHash, IncomingFile[] Files, Double HttpTimeoutMultiplier, NotifyReadDelegate NotifyRead)Wrapped by AggregateException: One or more errors occurred. (An error occurred while sending the request.)
at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)
at GitDependencies.Program.DownloadWorker(ConcurrentQueue`1 DownloadQueue, AsyncDownloadState State, Double HttpTimeoutMultiplier, Int32 MaxRetries, CancellationToken CancellationToken)
查看该指令相关的命令配置
UnrealEngine\Engine\Binaries\DotNET\GitDependencies\win-x64>GitDependencies.exe --help
Usage:
GitDependencies [options]
Options:
--all Sync all folders
--include=<X> Include binaries in folders called <X>
--exclude=<X> Exclude binaries in folders called <X>
--prompt Prompt before overwriting modified files
--force Always overwrite modified files
--root=<PATH> Set the repository directory to be sync
--threads=<N> Use N threads when downloading new files
--dry-run Print a list of outdated files and exit
--http-timeout-multiplier=<N> Override download timeout multiplier
--max-retries Override maximum number of retries per file
--proxy=<user:password@url> Sets the HTTP proxy address and credentials
--cache=<PATH> Specifies a custom path for the download cache
--cache-size-multiplier=<N> Cache size as multiplier of current download
--cache-days=<N> Number of days to keep entries in the cache
--no-cache Disable caching of downloaded files
Detected settings:
Excluded folders: none
Proxy server: none
Download cache: F:\dongshenghua\ue5.1\UnrealEngine\.git\ue-gitdeps
Default arguments can be set through the UE_GITDEPS_ARGS environment variable.
解决方案
增加如下的参数
--http-timeout-multiplier=120 延长超时时间
--cache=d:\cache 设置缓存,避免每次下载
--threads=10 多线程下载
--exclude=Linux --exclude=IOS --exclude=HTML5 --exclude=Android
5.2 执行最后出错
Checking dependencies (excluding Linux, IOS, HTML5, Android)...
Updating dependencies: 99% (40959/40960), 5982.3/6031.9 MiB | 0.00 MiB/s...
网上的解决方案
他们说源码路径太长了,只允许六个字节长度的路径
F:\dongshenghua\ue5.1\UnrealEngine\Engine\Binaries\Win64
我的解决方案
重新启动命令行窗口
5.3Would you like to overwrite your changes (y/n)? y
因为烘培过程中提示出错,SDK未安装,想着是否是没有完整安装的缘故,将依赖项IOS/Linux等重新安装
The following file(s) have been modified:
Engine/Binaries/DotNET/EpicGames.Perforce.Native/win-x64/Debug/EpicGames.Perforce.Native.dll
5.4Specified argument was out of the range of valid values
Updating dependencies: 46% (5122/5127), 794.1/2213.7 MiB | 1.05 MiB/s, 431.2 MiB cached...
Failed to download 'https://cdn.unrealengine.com/dependencies/UnrealEngine-23901901/b645fcb8d128dfacf83e05c83d05cc377a1db7f8': ArgumentOutOfRangeException: Specified argument was out of the range of valid values. (Parameter 'value')
at System.Net.Http.HttpClient.set_Timeout(TimeSpan value)
at GitDependencies.Program.DownloadAndExtractFiles(String Url, Uri Proxy, String CacheFileName, Int64 CompressedSize, String ExpectedHash, IncomingFile[] Files, Double HttpTimeoutMultiplier, NotifyReadDelegate NotifyRead)Wrapped by AggregateException: One or more errors occurred. (Specified argument was out of the range of valid values. (Parameter 'value'))
at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)
at GitDependencies.Program.DownloadWorker(ConcurrentQueue`1 DownloadQueue, AsyncDownloadState State, Double HttpTimeoutMultiplier, Int32 MaxRetries, CancellationToken CancellationToken)
6执行GenerateProjectFiles.bat
Visual Studio 2019 does not support .NET 6.0 C# projects, these projects will not be added to the generated solution.
Please generate the Visual Studio 2022 solution if .NET 6.0 C# project support is required.
顺利的话,完全执行以后,会自动退出
7UE5.sln
当出现UE5.sln解决方案说明,可以正常编译UE源码了
8 编译完成
耗时一个半小时,编译出UE编辑器
UnrealEngine\Engine\Binaries\Win64\UnrealEditor.exe
说明已经成功!
9注册引擎(非必需)
默认情况下,编译完成,鼠标右键点击项目工程.uproject文件,下拉列表选择Switch Unreal Engine version,就可以看到源码版本引擎
问题:打开项目选Switch找不到编译的源码版本
解决方案:源码编译目录下Engine\Binaries\Win64目录下运行UnrealVersionSelector-Win64-Shipping.exe,选择是,提示注册成功
参考
UnrealVersionSelector | 虚幻社区知识库 (ue5wiki.com)
9提示无法烘培,缺少SDK
该问题跟SDK无关,采用官网下载的5.1发布版本UE没有问题,源码不管采用VS2019还是是VS2022都提示相同的错误
备注:5.0版本源码烘培资源没有这个问题
10 Failed to initialize the engine (PreInit failed)
11禁用优化选项
例如调试Slate代码
修改文件UnrealEngine\Engine\Source\Runtime\Slate\Slate.Build.cs
增加一行代码
if (Target.bBuildDeveloperTools)
{
DynamicallyLoadedModuleNames.Add("Settings");
}
//增加代码如下
OptimizeCode = CodeOptimization.Never;
}
}
12 Failed to find command Turnkey
Starting AutomationTool...
Parsing command line: -ScriptsForProject=F:/dongshenghua/xihuan/XiHuan/XiHuan.uproject Turnkey -utf8output -WaitForUATMutex -command=VerifySdk -ReportFilename=F:/dongshenghua/xihuan/XiHuan/Intermediate/TurnkeyReport_2.log -log=F:/dongshenghua/xihuan/XiHuan/Intermediate/TurnkeyLog_2.log -project=F:/dongshenghua/xihuan/XiHuan/XiHuan.uproject -Device=HoloLens@https://192.168.11.152:50443/ -nocompile -nocompileuat
Initializing script modules...
Script module "F:\dongshenghua\ue5.1\UnrealEngine\Engine\Binaries\DotNET\AutomationTool\AutomationScripts\Platforms\IOS\IOS.Automation.dll" not found for record "F:\dongshenghua\ue5.1\UnrealEngine\Engine\Intermediate\ScriptModules\IOS.Automation.json"
Script module "F:\dongshenghua\ue5.1\UnrealEngine\Engine\Binaries\DotNET\AutomationTool\AutomationScripts\Platforms\TVOS\TVOS.Automation.dll" not found for record "F:\dongshenghua\ue5.1\UnrealEngine\Engine\Intermediate\ScriptModules\TVOS.Automation.json"
Total script module initialization time: 0.44 s.
Executing commands...
ERROR: Failed to find command Turnkey
(see F:\dongshenghua\ue5.1\UnrealEngine\Engine\Programs\AutomationTool\Saved\Logs\Log.txt for full exception trace)
AutomationTool executed for 0h 0m 0s
AutomationTool exiting with ExitCode=1 (Error_Unknown)
BUILD FAILED
==============================================================================
ERROR: Failed to find command Turnkey
(see F:\dongshenghua\ue5.1\UnrealEngine\Engine\Programs\AutomationTool\Saved\Logs\Log.txt for full exception trace)
AutomationException: Failed to find command Turnkey
at AutomationTool.Automation.ExecuteAsync(List`1 CommandsToExecute, Dictionary`2 Commands) in F:\dongshenghua\ue5.1\UnrealEngine\Engine\Source\Programs\AutomationTool\AutomationUtils\Automation.cs:line 250
at AutomationTool.Automation.ProcessAsync(ParsedCommandLine AutomationToolCommandLine, StartupTraceListener StartupListener, HashSet`1 ScriptModuleAssemblies) in F:\dongshenghua\ue5.1\UnrealEngine\Engine\Source\Programs\AutomationTool\AutomationUtils\Automation.cs:line 156