在我的的Unrealengine帳戶中關聯本身的GitHub帳戶成功以後,就能夠訪問UE4引擎的源碼了。html
git clone -b release https://github.com/EpicGames/UnrealEngine.git
克隆成功後,執行Setup.bat拉取並安裝外部依賴文件(第三方庫、資源包、示例工程等),最後調用UnrealVersionSelector添加引擎到註冊表並在資源管理器中添加引擎快捷菜單功能node
"%EngineDir%\Engine\Binaries\Win64\UnrealVersionSelector-Win64-Shipping.exe" /register
若須要設置代理能夠傳入相應參數來執行Setup.bat腳本 // Setup.bat會調用Engine\Binaries\DotNET\GitDependencies.exe工具來獲取依賴文件git
Setup.bat --proxy="http://10.125.224.93:8082" --force --exclude=Win32
注:若是是UE4.22版本,須要安裝.net framework 4.6.2,安裝完後在控制面板卸載列表中會有以下軟件列表:github
執行GenerateProjectFiles.bat生成UE4相關工程,生成的vs工程文件在Engine\Intermediate\ProjectFiles目錄中windows
雙擊UE4.sln,開始編譯相關工具和引擎 // 編譯的中間文件生成在EngineSource\Engine\Intermediate\Build目錄中api
編譯UnrealBuildTool服務器
"C:\Windows\Microsoft.NET\Framework64\v4.0.30319\msbuild.exe" "%EngineDir%\Engine\Source\Programs\UnrealBuildTool\UnrealBuildTool.csproj" /t:build /p:Configuration=Development;Platform=AnyCPU;TargetFrameworkVersion=v4.5
編譯引擎工具編輯器
"%EngineDir%\Engine\Binaries\DotNET\UnrealBuildTool.exe" ShaderCompileWorker Win64 Development -waitmutex -FromMsBuild -DEPLOY "%EngineDir%\Engine\Binaries\DotNET\UnrealBuildTool.exe" UnrealLightmass Win64 Development -waitmutex -FromMsBuild -DEPLOY "%EngineDir%\Engine\Binaries\DotNET\UnrealBuildTool.exe" UnrealIdentifierRegister Win64 Development -waitmutex -FromMsBuild -DEPLOY "%EngineDir%\Engine\Binaries\DotNET\UnrealBuildTool.exe" UnrealVersionSelector Win64 Development -waitmutex -FromMsBuild -DEPLOY
使用UnrealVersionSelector添加引擎到註冊表並在資源管理器上下文菜單中添加引擎快捷功能工具
"%EngineDir%\Engine\Binaries\DotNET\UnrealVersionSelector.exe" /register
1. 對uproject文件進行右鍵菜單註冊優化
2. 註冊uproject文件所用的引擎路徑
編譯引擎和項目
編譯Development版本的UE4引擎 // 會在%EngineDir%\Binaries\Win64和%EngineDir%\Plugins\*\···\*\Binaries\Win64目錄中生成引擎UE4Editor.exe、核心dll模塊和引擎插件dll
"%EngineDir%\Engine\Binaries\DotNET\UnrealBuildTool.exe" UE4Editor Win64 Development -waitmutex -FromMsBuild -DEPLOY
生成項目MyGame的vs項目工程文件 // 工程文件會生成到"%GameDir%\Intermediate\ProjectFiles"目錄中
"%EngineDir%\Engine\Binaries\Win64\UnrealVersionSelector.exe" /projectfiles "%GameDir%\MyGame.uproject"
編譯項目MyGame項目的Development版本 // 會在%GameDir%\Binaries\Win64和%GameDir%\Plugins\*\···\*\Binaries\Win64目錄中生成項目dll和項目插件dll
"%EngineDir%\Engine\Binaries\DotNET\UnrealBuildTool.exe" MyGameEditor Win64 Development "%GameDir%\MyGame.uproject" -waitmutex -FromMsBuild -DEPLOY
編譯單個c/cpp文件
"%EngineDir%\Engine\Binaries\DotNET\UnrealBuildTool.exe" MyGameEditor Win64 Development "%GameDir%\MyGame.uproject" -singlefile="%GameDir%\Source\MyGame\MyGameCharacter.cpp" -WaitMutex -FromMsBuild -DEPLOY
編譯單個模塊
"%EngineDir%\Engine\Binaries\DotNET\UnrealBuildTool.exe" -Module=MyGame Win64 Development -TargetType=Editor -Project="%GameDir%\MyGame.uproject" -canskiplink "%GameDir%\MyGame.uproject"
編譯單個引擎模塊
"%EngineDir%\Engine\Binaries\DotNET\UnrealBuildTool.exe" -Module=Engine Win64 Development -TargetType=Editor -Project="%GameDir%\MyGame.uproject" -canskiplink -nosharedpch "%GameDir%\MyGame.uproject"
編譯多個模塊
"%EngineDir%\Engine\Binaries\DotNET\UnrealBuildTool.exe" -Module=MyCommon -Module=MyGame Win64 Development -TargetType=Editor -Project="%GameDir%\MyGame.uproject" -canskiplink "%GameDir%\MyGame.uproject"
一些技巧
(1)去掉UE4和遊戲工程的全部Depends(工程右鍵菜單 -- Build Dependencies -- Project Dependencies ...),手動編譯各個工程,防止修改一個工程後,引起依賴該工程發生重編譯
(2)編譯時不要用滿全部cpu的核,不然計算機會很是卡,基本沒法進行其餘工做
在BuildConfiguration.xml中進行配置,將MaxProcessorCount設置成7(我本機是8核cpu)
<?xml version="1.0" encoding="utf-8" ?> <Configuration xmlns="https://www.unrealengine.com/BuildConfiguration"> <ParallelExecutor> <MaxProcessorCount>7</MaxProcessorCount> </ParallelExecutor> </Configuration>
BuildConfiguration.xml會按照下面路徑的順序來進行查找來加載 更多信息詳見:Build Configuration
① 引擎工程:Engine/Saved/UnrealBuildTool/BuildConfiguration.xml
② <User Folder>/AppData/Roaming/Unreal Engine/UnrealBuildTool/BuildConfiguration.xml
③ <My Documents>/Unreal Engine/UnrealBuildTool/BuildConfiguration.xml
(3)從vs直接運行或調試運行UE時,不要進行任何編譯行爲
運行引擎和項目
啓動引擎編輯器
"%EngineDir%/Engine/Binaries/Win64/UE4Editor.exe" -skipcompile
啓動項目編輯器
"%EngineDir%/Engine/Binaries/Win64/UE4Editor.exe" "%GameDir%\MyGame.uproject" -skipcompile
單機啓動遊戲單機
"%EngineDir%/Engine/Binaries/Win64/UE4Editor.exe" "%GameDir%\MyGame.uproject" TestMap_Main -game -skipcompile
啓動本地ds
"%EngineDir%/Engine/Binaries/Win64/UE4Editor.exe" "%GameDir%\MyGame.uproject" TestMap_Main -game -server -log -skipcompile
啓動遊戲並聯網加入本地ds
"%EngineDir%/Engine/Binaries/Win64/UE4Editor.exe" "%GameDir%\MyGame.uproject" 127.0.0.1 -game -skipcompile
版本打包
① win64 -- Development版本包 會輸出到%Win64Dir%\WindowsNoEditor目錄中
%EngineDir%\Engine\Build\BatchFiles\RunUAT.bat -ScriptsForProject=%GameDir%\MyGame.uproject BuildCookRun -project=%GameDir%\MyGame.uproject -targetplatform=Win64 -clientconfig=Development -ue4exe=UE4Editor-Cmd.exe -noP4 -iterate -cook -pak -package -stage -archive -archivedirectory=%Win64Dir% -nocompileeditor -prereqs -nodebuginfo -build -CrashReporter -utf8output -compressed
② Android -- Debug版本包 會輸出到%ApkDir%\Android_ETC2目錄中 windows下安裝Android構建環境
%EngineDir%\Engine\Build\BatchFiles\RunUAT.bat -ScriptsForProject=%GameDir%\MyGame.uproject BuildCookRun -nocompileeditor -nop4 -iterate -project=%GameDir%\MyGame.uproject -cook -stage -archive -archivedirectory=%ApkDir% -package -clientconfig=Debug -ue4exe=UE4Editor-Cmd.exe -compressed -pak -prereqs -nodebuginfo -targetplatform=Android -cookflavor=ETC2 -build -distribution -utf8output -compile
③ iOS -- Debug版本包 會輸出到${IpaDir}/IOS目錄中 注:設置DefaultGame.ini中[/Script/UnrealEd.ProjectPackagingSettings]標籤下的BuildConfiguration=PPBC_Debug
${%EngineDir%}/Engine/Build/BatchFiles/RunUAT.sh -ScriptsForProject=${GameDir}/MyGame.uproject BuildCookRun -nocompileeditor -nop4 -project=${GameDir}/MyGame.uproject -cook -stage -archive -archivedirectory=${IpaDir} -package -clientconfig=Debug -ue4exe=UE4Editor -compressed -pak -prereqs -nodebuginfo -targetplatform=IOS -build -manifests -CrashReporter -utf8output -compile
④ Linux ds -- Debug版本包 會輸出到${LinuxDir}目錄中
${%EngineDir%}/Engine/Build/BatchFiles/RunUAT.sh BuildCookRun -project=${GameDir}/MyGame.uproject -build -cook -pak -stage -archive -archivedirectory=${LinuxDir} -package -serverconfig=Debug -server -noclient -targetplatform=Linux -ue4exe=UE4Editor -prereqs -nop4 -utf8output
其餘
清理Development版本的UE4引擎
"%EngineDir%\Engine\Build\BatchFiles\Clean.bat" UE4Editor Win64 Development -waitmutex
清理Development版本的MyGame項目
"%EngineDir%\Engine\Build\BatchFiles\Clean.bat" MyGameEditor Win64 Development "%GameDir%\MyGame.uproject" -waitmutex
爲MyGame項目的TestMap_Main地圖構建光照
"%EngineDir%\Engine\Build\BatchFiles\RunUAT.bat" RebuildLightmaps -project=%GameDir%\MyGame.uproject -MapsToRebuildLightMaps=TestMap_Main
找不到XINPUT1_3.dll
安裝引擎目錄下Engine\Extras\Redist\en-us\UE4PrereqSetup_x64.exe
關於解決方案的Configuration
1. Debug 遊戲模塊和引擎模塊均開啓調試模式
2. DebugGame 遊戲模塊開啓調試模式,引擎模板開啓優化
3. Development 遊戲模塊和引擎模塊均開啓優化
4. Shipping 發行版本(會去掉全部編輯器功能、stat統計以及GM命令等)遊戲模塊和引擎模塊均開啓優化
5. 帶Editor表示爲編輯器版本(含有不少編輯器相關的功能)
6. 帶Client表示爲客戶端版本
7. 帶Server表示爲服務器版本