UE4游戲開發基礎命令


在個人的Unrealengine賬戶中關聯自己的GitHub賬戶成功之后,就可以訪問UE4引擎的源碼了。

git clone -b release https://github.com/EpicGames/UnrealEngine.git

克隆成功后,執行Setup.bat拉取並安裝外部依賴文件(第三方庫、資源包、示例工程等),最后調用UnrealVersionSelector添加引擎到注冊表並在資源管理器中添加引擎快捷菜單功能

"%EngineDir%\Engine\Binaries\Win64\UnrealVersionSelector-Win64-Shipping.exe" /register

若需要設置代理可以傳入相應參數來執行Setup.bat腳本 // Setup.bat會調用Engine\Binaries\DotNET\GitDependencies.exe工具來獲取依賴文件

Setup.bat --proxy="http://10.125.224.93:8082" --force --exclude=Win32

注:如果是UE4.22版本,需要安裝.net framework 4.6.2,安裝完后在控制面板卸載列表中會有如下軟件列表:

執行GenerateProjectFiles.bat生成UE4相關工程,生成的vs工程文件在Engine\Intermediate\ProjectFiles目錄中

雙擊UE4.sln,開始編譯相關工具和引擎  // 編譯的中間文件生成在EngineSource\Engine\Intermediate\Build目錄中

 

編譯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

mac下使用mono提供的xbuild工具編譯UnrealBuildTool

/Users/<用戶>/Engine/Binaries/ThirdParty/Mono/Mac/bin/xbuild /Users/<用戶>/Engine/Source/Programs/UnrealBuildTool/UnrealBuildTool.csproj /property:Configuration="Development" /verbosity:quiet /nologo

 

編譯引擎工具

"%EngineDir%\Engine\Binaries\DotNET\UnrealBuildTool.exe" ShaderCompileWorker Win64 Development -waitmutex -FromMsBuild -DEPLOY  // Windows下編譯ShaderCompileWorker

"%EngineDir%\Engine\Binaries\DotNET\UnrealBuildTool.exe" UnrealLightmass Win64 Development -waitmutex -FromMsBuild -DEPLOY  // Windows下編譯UnrealLightmass

"%EngineDir%\Engine\Binaries\DotNET\UnrealBuildTool.exe" UnrealIdentifierRegister Win64 Development -waitmutex -FromMsBuild -DEPLOY  // Windows下編譯UnrealIdentifierRegister

"%EngineDir%\Engine\Binaries\DotNET\UnrealBuildTool.exe" UnrealVersionSelector Win64 Development -waitmutex -FromMsBuild -DEPLOY  // Windows下編譯UnrealVersionSelector

mono $EngineDir/Engine/Binaries/DotNET/UnrealBuildTool.exe ShaderCompileWorker Mac Development  // Mac下編譯ShaderCompileWorker

 

使用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

生成了UE4.sln或UE4.xcworkspace,也可以使用msbuild.exe或xcodebuild來編譯  

// vs2017的msbuild所在目錄:Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin
msbuild.exe UE4.sln /p:Configuration="Development Editor" /p:Platform=Win64 /m:8  // 使用並發線程數為8,編譯配置為:Development Editor Win64來編譯生成UE4Editor.exe

xcodebuild -workspace UE4.xcworkspace/ -scheme UE4 -configuration "Development Editor" // xcode下編譯Development Editor的UE4Editor

xcode編譯出的UE4Editor所在目錄:%EngineDir%/Binaries/Mac/UE4Editor.app/Contents/MacOS/UE4Editor

 

生成項目MyGame的vs項目工程文件  // 工程文件會生成到"%GameDir%\Intermediate\ProjectFiles"目錄中

"%EngineDir%\Engine\Binaries\Win64\UnrealVersionSelector.exe" /projectfiles "%GameDir%\MyGame.uproject"   //windows下

"%EngineDir%/GenerateProjectFiles.sh" -project="%GameDir%/MyGame.uproject" -Game -Engine // Mac或Linux下

"%EngineDir%/GenerateProjectFiles.sh" -project="%GameDir%/MyGame.uproject" -platforms=IOS -game -nointellisense -IOSdeployonly -ignorejunk -projectfileformat=XCode -includetemptargets  // Mac下專有IOS工程 

編譯項目MyGame的Development Editor版本  // 會在%GameDir%\Binaries\Win64和%GameDir%\Plugins\*\···\*\Binaries\Win64目錄中生成項目dll和項目插件dll

"%EngineDir%\Engine\Binaries\DotNET\UnrealBuildTool.exe" MyGameEditor Win64 Development "%GameDir%\MyGame.uproject" -waitmutex -FromMsBuild -DEPLOY // windows下

$EngineDir/Engine/Build/BatchFiles/Mac/XcodeBuild.sh MyGameEditor macosx Development $GameDir%/MyGame.uproject // Mac下

mono $EngineDir/Engine/Binaries/DotNET/UnrealBuildTool.exe  MyGameEditor macosx Development $GameDir%/MyGame.uproject // Mac下

 

編譯單個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" 

編譯項目MyGame的客戶端版本

"%EngineDir%\Engine\Binaries\Win64\UnrealVersionSelector.exe" MyGame Win64 Development -Project="%GameDir%\MyGame.uproject"

編譯項目MyGame的Linux Server版本

mono "%EngineDir%\Engine\Binaries\DotNET\UnrealBuildTool.exe" MyGameServer Linux Development -Project="%GameDir%\MyGame.uproject"

構建安裝版引擎

%EngineDir%\Engine\Build\BatchFiles\RunUAT.bat BuildGraph -target="Make Installed Build Win64" -script=Engine/Build/InstalledEngineBuild.xml -set:WithMac=false -set:WithAndroid=false -set:WithIOS=false -set:WithTVOS=false -set:WithLinux=false -set:WithHTML5=false -set:WithSwitch=false -WithDDC=false -set:WithWin32=false -set:WithLumin=false -set:WithPS4=false -set:WithXboxOne=false -set:WithHoloLens=false -set:GameConfigurations=Development

 

配置文件詳見 :Engine/Build/InstalledEngineBuild.xml

構建好的安裝版引擎在:%EngineDir%\LocalBuilds\Engine\Windows目錄中

 

一些log

UnrealHeaderTool:UnrealEngine\Engine\Programs\UnrealHeaderTool\Saved\Logs\UnrealHeaderTool.log

UnrealBuildTool:UnrealEngine\Engine\Programs\UnrealBuildTool\Log.txt

UAT:UnrealEngine\Engine\Programs\AutomationTool\Saved\Logs\Log.txt

          UnrealEngine\Engine\Programs\AutomationTool\Saved\Logs\Cook-2020.07.13-17.32.30.txt

MyGame:MyGame\Saved\Logs\MyGame.log

 

Mac osx上的log

UnrealHeaderTool:~\Library\Logs/Unreal Engine/UnrealHeaderTool/UnrealHeaderTool.log

UnrealBuildTool:UnrealEngine\Engine\Programs\UnrealBuildTool\Log.txt

UAT:~\Library\Logs/Unreal Engine/LocalBuildLogs中,包含一下一些文件

Cook-2020.07.13-17.46.05.txt   // Cook資源的log
FinalCopy_NonUFSFiles.txt
FinalCopy_NonUFSFilesDebug.txt
FinalCopy_UFSFiles.txt
Log.txt    // 編譯ios版本的log
Manifest_NonUFSFiles_IOS.txt
PakList_basicasset-ios.txt
PakList_uagame-ios.txt
PrePak_IOS_NonUFSFiles.txt
PrePak_IOS_NonUFSFilesDebug.txt
PrePak_IOS_UFSFiles.txt
UBT-UAGame-IOS-Development.txt
UBT-UnrealPak-Mac-Development.txt
UnrealPak-basicasset-ios-2020.07.13-17.47.12.txt
UnrealPak-uagame-ios-2020.07.13-17.47.12.txt

 

 

MyGame:~\Library\Logs/Unreal Engine/MyGameEditor/MyGame.log

 

一些技巧

(1)去掉UE4和游戲工程的所有Depends(工程右鍵菜單 -- Build Dependencies -- Project Dependencies ...),手動編譯各個工程,防止修改一個工程后,引發依賴該工程發生重編譯

(2)Tools - Options - Projects and Solutions,取消勾選Always show Error List if build finishes with errors,防止每次編譯有錯,vs都自動激活顯示Error List面板

(3)將Solution Configurations的寬度調成為150,讓其能顯示完全

         菜單項:Tools - Options - Customize

(4)編譯時不要用滿所有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>
     <BuildConfiguration>
         <bAllowXGE>true</bAllowXGE>
     </BuildConfiguration>
 </Configuration>

 注:bAllowXGE表示是否開啟IncredBuild

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

還有一種快速禁掉IncredBuild方法是將c:\Programe Files(x86)\IncredBuild\xgConsole.exe改名

(5)如果只是想禁用shader編譯的IncredBuild的加速,可在Engine\Config\ConsoleVariables.ini中打開r.XGEShaderCompile = 0

(6)從vs直接運行或調試運行UE時,不要進行任何編譯行為

(7)UnrealVS擴展中文

右鍵Visual Studio工具欄區域,彈出快捷菜單,勾選顯示UnrealVS工具欄

安裝文件在:Engine\Extras\UnrealVS

代碼在:Engine\Source\Programs\UnrealVS

提供了如下功能:

a. 設置啟動項目
b. 綁定構建啟動項目的命令
c. 設置命令行參數
d. 批量構建項目
f. 快速構建項目菜單

(8)出現斷點打不上(空心帶黃色感嘆號)的情況(如:調試Release版本、可執行程序目錄發生過變化等),需要做一下檢查和設置

① vs處於調試態時,在菜單Debug -- Windows -- Modules面板里,搜索目標模塊的pdb是否加載

② vs設置:Tools - Options - Debugging  -  取消勾選“Require source files to exactly match the original version”

(9)改善C++調試:在vs進行C++調試時更好地查看Unreal自定義類型變量(如:FName,FString,TArray等)

運行Engine\Extras\VisualStudioDebugging\InstallVisualizers.bat(支持vs2012、vs2013、vs2015)進行安裝

對於vs2017等更高版本,可以手動將Engine\Extras\VisualStudioDebugging\UE4.natvis拷貝到%USERPROFILE%\Documents\Visual Studio 2017\Visualizers目錄中進行手動安裝

安裝完成后,重啟vs

vs設置:Tools - Options - Debugging  -  取消勾選“Show raw structure of objects in variables windows”

(10)開啟vs的Intellisense(智能感知)功能

在編寫代碼實時鍵入時,IntelliSense將重新編譯C++,進行實時錯誤和篩選。此功能比VAX的語法檢查更加強大,其使用的是完整C++編譯器,可逐行驗證代碼,可極大加快工作流

注1:左下角的圖標表示圖標IntelliSense編譯程序正在運行

注2:vs默認是開啟Intellisense的,如果沒有啟用,請檢查以下設置項

(11)配置並使用ue4的Snippet自動完成,來插入模板代碼

配置方法:拷貝Engine\Extras\VisualStudioSnippets中所有的snippet文件到C:\Users\<user>\Documents\Visual Studio 2017\Code Snippets\Visual C++\My Code Snippets目錄中,並重啟vs

然后在UE4的項目中輸入:ue4  就會出現snippet列表,選擇某項snippet后就會插入對應模板代碼

擴展:ue4snippets github    Snippet各個文件說明

 

更多請參考:設置虛幻引擎的Visual Studio中文

 

運行引擎和項目

啟動引擎編輯器

"%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構建環境 (en

%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

環境變量 -- XXX的用戶變量:

ANDROID_HOME    E:\NVPACK\android-sdk-windows
ANDROID_NDK_ROOT    E:\NVPACK\android-ndk-r14b
ANT_HOME     E:\NVPACK\apache-ant-1.8.2
GRADLE_HOME    E:\NVPACK\gradle-2.9
JAVA_HOME    E:\NVPACK\jdk1.8.0_77
NDK_ROOT    E:\NVPACK\android-ndk-r14b
NDKROOT    E:\NVPACK\android-ndk-r14b
NVPACK_NDK_TOOL_VERSION    4.9
NVPACK_NDK_VERSION    android-ndk-r14b
NVPACK_ROOT    E:\\NVPACK
Path    E:\NVPACK\gradle-2.9\bin;E:\NVPACK\apache-ant-1.8.2\bin;E:\NVPACK\jdk1.8.0_77\bin;E:\NVPACK\android-ndk-r14b;E:\NVPACK\android-sdk-windows\extras\android\support;E:\NVPACK\android-sdk-windows\build-tools;E:\NVPACK\android-sdk-windows\platform-tools;E:\NVPACK\android-sdk-windows\tools;

注:若想升級ndk,可從這兒下載,解壓后放到E:\NVPACK目錄中,並更新NDK_ROOT、NDKROOT及Path環境變量中的路徑即可

在項目設置 -- Platforms -- Android頁面中,點擊Accept SDK License同意一下   注:會在E:\NVPACK\android-sdk-windows\licenses下生成一個android-sdk-license文件

C:\Users\<用戶名>\.gradle目錄、C:\Users\<用戶名>\.android目錄

配置gradle的代理(所在文件:C:\Users\<用戶名>\.gradle\gradle.properties

systemProp.https.proxyPort=8080
systemProp.http.proxyHost=web-proxy.oa.com
systemProp.https.proxyHost=web-proxy.oa.com
systemProp.http.proxyPort=8080

③ 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

注:在windows配置好iOS遠程構建環境,也可以在windows上構建iOS版本  詳見:在 Windows 上構建 iOS 版本

④ 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

注1:cook的臨時文件存放在:%GameDir%\Saved\Cooked

注2:最后的版本存放在:%GameDir%\Archive

 

其他

清理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

在windows上重新打包和重簽名,生成ipa文件  注:ipa文件生成在%GameDir%\Binaries\IOS\MyGame.ipa

"%EngineDir%\Engine\Binaries\DotNET\IOS\IPhonePackager.exe" RepackageFromStage "%GameDir%\MyGame.uproject" -config Development -schemename MyGame -schemeconfig "Development" -sign -codebased -stagedir "%GameDir%\Saved\StagedBuilds\IOS" -project "%GameDir%\MyGame.uproject" -provision "DGame.mobileprovision" -certificate "iPhone Developer: cert RDM (CFG5EWN5ME)"

 

找不到XINPUT1_3.dll

安裝引擎目錄下Engine\Extras\Redist\en-us\UE4PrereqSetup_x64.exe

 

關於解決方案的Configuration

 

1. Debug 游戲模塊和引擎模塊均開啟調試模式

2. DebugGame  游戲模塊開啟調試模式,引擎模板開啟優化

3. Development  游戲模塊和引擎模塊均開啟優化

4. Shipping 發行版本(會去掉所有編輯器功能、stat統計、性能分析以及GM命令等)游戲模塊和引擎模塊均開啟優化

5. Test  含有stat統計、性能分析以及GM命令的Shipping版本

6. 帶Editor表示為編輯器版本(含有很多編輯器相關的功能) 使用MyGameEditor.Target.cs的項目配置

7. 都不帶表示為客戶端版本    使用MyGame.Target.cs的項目配置

8. 帶Server表示為服務器版本  使用MyGameServer.Target.cs的項目配置

 

在windows下編譯通過,而在其他Linux、Android、iOS等平台編譯不過的一些情況:

1. 斜杠問題

如:#include "Misc\FileHelper.h"   -->  #include "Misc/FileHelper.h"

2. 大小寫問題

如:#include "HAL/PlatformFileManager.h"  --> #include "HAL/PlatformFilemanager.h"

3. 非英文字符

如:UE_LOG(LogTemp, Warning, TEXT("test xx");  --> UE_LOG(LogTemp, Warning, TEXT("test (xx)");

4. 使用非UE4的類型

如:INT AmmoCount;   -->  int32 AmmoCount;

5. 使用L來修飾字符串

如:L"MyTools"  -->  TEXT("MyTools")

6. 缺少#include某些頭文件

原因是不同編譯器遞歸展開頭文件規則存在差別

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM