UE4游戏开发基础命令
转载:https://www.cnblogs.com/kekec/p/8684068.html
在个人的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目录中
用来存放UE4引擎和项目代码的目录的一些注意点:
1. 目录的全路径中不要包含中文、空格
2. 目录不要放置得太深,会导致编译链接的命令行太长的错误 注:可通过在模块的Build.cs中设置bLegacyPublicIncludePaths = false来缓解
3. 目录名要以英文或下划线开头(不能以数字开头):因为UHT会利用目录名做为其符号名(注:c++中变量名、函数名不能以数字开头)的一部分
编译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
注:当UnrealBuildTool不存在或其源码有修改时,执行引擎目录下的GenerateProjectFiles.bat或GenerateProjectFiles.sh会重新生成UnrealBuildTool
编译引擎工具
"%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
使用ShaderCompilerWorker.exe编译shader
%EngineDir%/Engine/Binaries/Win64/ShaderCompileWorker.exe <AppData>/Local/Temp/UnrealShaderWorkingDir/BFE18CAA45FA658BF12AE489BE247311/5/ 27472 5 WorkerInputOnly.in WorkerOutputOnly.out -communicatethroughfile -TimeToLive=20.000000 -Multiprocess
使用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的项目工程文件 // 工程文件会生成到”%GameDir%\Intermediate\ProjectFiles”目录中
"%EngineDir%\Engine\Binaries\Win64\UnrealVersionSelector.exe" /projectfiles "%GameDir%\MyGame.uproject" //windows下 "%EngineDir%/Engine/Binaries/DotNET/UnrealBuildTool.exe" -projectfiles -project="%GameDir%\MyGame.uproject" -game -engine -progress -log="%GameDir%/Saved/Logs/UnrealVersionSelector-2020.12.31-11.34.19.log" //windows下 "%EngineDir%/Engine/Binaries/DotNET/UnrealBuildTool.exe" -projectfiles -project="%GameDir%\MyGame.uproject" -game -engine -VSCode //windows下生成vscode项目工程 "%EngineDir%/Engine/Binaries/DotNET/UnrealBuildTool.exe" -projectfiles -project="%GameDir%\MyGame.uproject" -game -engine -2019 //windows下生成vs2019项目工程 "%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工程
注:windows下,可在UE4编辑器菜单File — Refresh Visual Studio Project来生成或刷新vs项目文件;在Mac下,可在UE4编辑器菜单File — Refresh XCode Project来生成或刷新xCode项目文件 【与上面命令是等价的】
编译项目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下
编译项目MyGame的Development Android版本(libUE4.so)
UnrealBuildTool.exe MyGame Android Development -Project=%GameDir%\MyGame.uproject"
编译项目MyGame的Debug IOS版本(MyGame可执行二进制)
mono $EngineDir$/Engine/Binaries/DotNET/UnrealBuildTool.exe MyGame IOS Debug -Project=$GameDir$/MyGame.uproject
遇到的问题:ld: can’t open -unexported_symbols_list file: /Users/xxx/Trunk/UAGroup/MyGame/unexported_symbols.txt
解决方法:在该目录下放置一个unexported_symbols.txt文件,里面内容如下:
*TSS* *Tss* *tss* *AceSDK* *MRPCS* *mrpcs* *tp2* *tcj* *_proto* *ns_tinyxml*
编译单个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:更多额外命令行参数见UnrealBuildTool中的GlobalOptions类中的CommandLine修饰的成员变量
-Verbose、-VeryVerbose、-Log、-Timestamps、-Progress、-NoMutex、-RemoteIni、-SkipDeploy、-Clean、
-ProjectFiles、-ProjectFileFormat=、-Makefile、-CMakefile、-QMakefile、-KDevelopfile、-CodeliteFiles、-XCodeProjectFiles、-EdditProjectFiles、-VSCode、-VSMac、-CLion
注2:更多额外命令行参数见UnrealBuildTool中的TargetDescriptor类中的CommandLine修饰的成员变量
-NoHotReload、-ForceHotReload、-LiveCoding、-WriteActions=c:\myAction.txt (输出编译链接过程中详细信息)
-mode=JsonExport(读取所有build.cs,输出modules的依赖关系)、-LiveCodingModules=modulelist.txt、-LiveCodingManifest=mymenifest.txt、-Quiet
// 编译链接出so文件,另外记录编译链接各命令行的日志文件会输出在c:\svn\myAction.txt C:\svn\UnrealEngine\Engine\Binaries\DotNET\UnrealBuildTool.exe UAGame Android Shipping -Project="C:\svn\R6Game\UAGame.uproject" -WriteActions="c:\svn\myAction.txt" // 不会编译链接出so文件,json文件会输出在C:\svn\R6Game\Binaries\Android\UAGame-Android-Shipping.json C:\svn\UnrealEngine\Engine\Binaries\DotNET\UnrealBuildTool.exe UAGame Android Shipping -Project="C:\svn\R6Game\UAGame.uproject" -mode=JsonExport
编译项目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目录中
注1:可放置一个%EngineDir%/Engine/Build/InstalledBuild.txt空文件,将当前引擎标识成一个InstalledEngine
注2:InstalledEngine主要用来提升团队开发效率,让构建机生产好这些二进制内容,而不需要每个人都来编译一遍。
① 引擎编辑器(UE4Editor.exe)、构建工具链(UBT、UHT、UAT)以及第三方工具(UnrealPak.exe、ShaderCompileWorker.exe、UnrealLightmass.exe等)
(a)引擎编辑器、第三方工具和UHT 在%EngineDir%/Engine/Binaries/Win64目录中
(b)UBT、UAT 在%EngineDir%/Engine/Binaries/DotNET目录中
② 引擎及项目依赖的所有模块的.h、.generated.h、.lib、.dll文件
(a).h 在%EngineDir%/Engine/Source、%EngineDir%/Engine/Plugins/<xxx>/Source目录中
(b).generated.h、.lib 在%EngineDir%/Engine/Intermediate、%EngineDir%/Engine/Plugins/<xxx>/Intermediate目录中
(c).dll 在%EngineDir%/Engine/Binaries/Win64、%EngineDir%/Engine/Plugins/<xxx>/Binaries/Win64目录中
注3:cpp代码不是必须的
UnrealPak
解压未加密的MyGame-Android_ASTC.pak包到%Output%/MyGame-Android_ASTC目录中
%EngineDir%/Engine/Binaries/Win64/UnrealPak.exe "%MyGame-arm64-es2%/assets/MyGame/Content/Paks/MyGame-Android_ASTC.pak" -Extract "%Output%/MyGame-Android_ASTC"
有Crypto.json秘钥文件时,解压加密的MyGame-Android_ASTC.pak包到%Output%/MyGame-Android_ASTC目录中
%EngineDir%/Engine/Binaries/Win64/UnrealPak.exe "%MyGame-arm64-es2%/assets/MyGame/Content/Paks/MyGame-Android_ASTC.pak" -Extract "%Output%/MyGame-Android_ASTC" -cryptokeys="%GameDir%/Saved/Cooked/Android_ASTC/MyGame/Metadata/Crypto.json"
无Crypto.json秘钥文件时,解压加密的MyGame-Android_ASTC.pak包到%Output%/MyGame-Android_ASTC目录中
%EngineDir%/Engine/Binaries/Win64/UnrealPak.exe "%MyGame-arm64-es2%/assets/MyGame/Content/Paks/MyGame-Android_ASTC.pak" -Extract "%Output%/MyGame-Android_ASTC" -encryptindex -encryptionini -projectdir="%GameDir%" -enginedir="%EngineDir%" -Platform=Windows
注1:该方式会通过读取%GameDir%/Config/DefaultCrypto.ini中的秘钥来解密
注2:需要在项目的%GameDir%/Config/DefaultEngine.ini中进行如下配置,来将项目标识为一个加密类型
UHT扫描头文件命令行
// UHT扫描UE4工程 "%EngineDir%\Engine\Binaries\Win64\UnrealHeaderToo.exe" UE4Editor "%EngineDir%\Engine\Intermediate\Build\Win64\UE4Editor\DebugGame\UE4Editor.uhtmanifest" -LogCmds="loginit warning, logexit warning, logdatabase error" -Unattended -WarningsAsErrors -abslog="%EngineDir%\Engine\Programs\UnrealBuildTool\Log_UHT.txt" // UHT扫描MyGame项目工程 "%EngineDir%\Engine\Binaries\Win64\UnrealHeaderTool.exe" "%GameDir%\MyGame.uproject" "%GameDir%\Intermediate\Build\Win64\MyGameEditor\DebugGame\MyGameEditor.uhtmanifest" -LogCmds="loginit warning, logexit warning, logdatabase error" -Unattended -WarningsAsErrors -abslog="%EngineDir%\Engine\Programs\UnrealBuildTool\Log_UHT.txt" // UHT扫描ShaderCompileWorker工程 "%EngineDir%\Engine\Binaries\Win64\UnrealHeaderTool.exe" ShaderCompileWorker "%EngineDir%\Engine\Intermediate\Build\Win64\ShaderCompileWorker\Development\ShaderCompileWorker.uhtmanifest" -LogCmds="loginit warning, logexit warning, logdatabase error" -Unattended -WarningsAsErrors -abslog="%EngineDir%\Engine\Programs\UnrealBuildTool\Log_UHT.txt"
一些log
UnrealHeaderTool:UnrealEngine\Engine\Programs\UnrealHeaderTool\Saved\Logs\UnrealHeaderTool.log
UnrealBuildTool:UnrealEngine\Engine\Programs\UnrealBuildTool\Log.txt
AppData\Local\UnrealBuildTool\Log.txt(InstalledEngine)
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)不要把DDC(Derived Data Cache)目录设置到机械硬盘上,要放在SSD上,否则使用编辑器时会很卡(如:移动场景中的物体) 注:其缺省会在<User Folder>/AppData/Local/UnrealEngine中
(2)去掉UE4和游戏工程的所有Depends(工程右键菜单 — Build Dependencies — Project Dependencies …),手动编译各个工程,防止修改一个工程后,引发依赖该工程发生重编译
(3)去掉UE4和游戏工程NMake命令行上的对ShaderCompileWorker的依赖
可在引擎工程:Engine/Saved/UnrealBuildTool/BuildConfiguration.xml中关闭Generate Visual Studio Project files时对ShaderCompileWorker的依赖
<?xml version="1.0" encoding="utf-8" ?> <Configuration xmlns="https://www.unrealengine.com/BuildConfiguration"> <BuildConfiguration> <bEditorDependsOnShaderCompileWorker>false</bEditorDependsOnShaderCompileWorker> </BuildConfiguration> </Configuration>
(4)关闭每次构建项目都自动构建UnrealHeaderTool
在Engine/Saved/UnrealBuildTool/BuildConfiguration.xml中增加如下配置:
<?xml version="1.0" encoding="utf-8" ?> <Configuration xmlns="https://www.unrealengine.com/BuildConfiguration"> <UEBuildConfiguration> <bDoNotBuildUHT>true</bDoNotBuildUHT> </UEBuildConfiguration> </Configuration>
注:从UnrealHeaderTool.Build.cs中可知:UHT依赖6个基础的引擎模块:Core、CoreUObject、Json、Projects、TraceLog(Core、CoreUObject依赖TraceLog,所以UHT也间接依赖它)和BuildSettings(Core依赖BuildSettings,所以UHT也间接依赖它)
(5)Tools – Options – Projects and Solutions,取消勾选Always show Error List if build finishes with errors,防止每次编译有错,vs都自动激活显示Error List面板
(6)关闭Visual Studio自带git插件,避免每次编译都要进行git status的检查,提升开发效率
1>------ Build started: Project: MyTest1, Configuration: Debug_Editor x64 ------ 1>Using 'git status' to determine working set for adaptive non-unity build (G:\svn\UnrealEngine). 1>Using 'git status' to determine working set for adaptive non-unity build (G:\svn\MyTest1). 1>Waiting for 'git status' command to complete
(7)将Solution Configurations的宽度调成为150,让其能显示完全
菜单项:Tools – Options – Customize
(8)编译时不要用满所有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(XGE)
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改名
(9)如果只是想禁用shader编译的IncredBuild的加速,可在Engine\Config\ConsoleVariables.ini中打开r.XGEShaderCompile = 0
(10)从vs直接运行或调试运行UE时,不要进行任何编译行为
11)UnrealVS扩展(中文)
右键Visual Studio工具栏区域,弹出快捷菜单,勾选显示UnrealVS工具栏
安装文件在:Engine\Extras\UnrealVS
代码在:Engine\Source\Programs\UnrealVS
提供了如下功能:
a. 设置启动项目
b. 绑定构建启动项目的命令
c. 设置命令行参数
d. 批量构建项目
f. 快速构建项目菜单
(12)出现断点打不上(空心带黄色感叹号)的情况(如:调试Release版本、可执行程序目录发生过变化等),需要做一下检查和设置
① vs处于调试态时,在菜单Debug — Windows — Modules面板里,搜索目标模块的pdb是否加载
② vs设置:Tools – Options – Debugging – 取消勾选“Require source files to exactly match the original version”
(13)改善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”
(14)开启vs的Intellisense(智能感知)功能
在编写代码实时键入时,IntelliSense将重新编译C++,进行实时错误和筛选。此功能比VAX的语法检查更加强大,其使用的是完整C++编译器,可逐行验证代码,可极大加快工作流
注1:左下角的图标表示图标IntelliSense编译程序正在运行
注2:vs默认是开启Intellisense的,如果没有启用,请检查以下设置项
(15)配置并使用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 githubSnippet各个文件说明
(16)禁用“编译出错时始终显示错误列表”(Always show Error List if build finishes with error) 注:防止编译失败后自动弹出错误列表
(17)Disable显示非活动代码块 注:关闭该选项后,代码会正常显示(#if 为false的代码块会变灰)
更多请参考:设置虚幻引擎的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
"%EngineDir%\Engine\Binaries\Win64\UE4Editor.exe" "%GameDir%/MyGame.uproject" /Game/TestMap -game -PIEVIACONSOLE -Multiprocess GameUserSettingsINI="%GameDir%/Saved/Config/Windows/PIEGameUserSettings0.ini" -MultiprocessSaveConfig -MultiprocessOSS -messaging -SessionName="Play in Standalone Game" -windowed -WinX=309 -WinY=152 SAVEWINPOS=1 -ResX=1280 -ResY=720
启动本地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
cook Android ASTC包命令:
%EngineDir%\Engine\Binaries\Win64\UE4Editor-Cmd.exe %GameDir%\MyGame.uproject -run=Cook -TargetPlatform=Android_ASTC -fileopenlog -unversioned -abslog=%EngineDir%\Engine\Programs\AutomationTool\Saved\Cook-2020.12.08-09.48.23.txt -stdout -CrashForUAT -unattended -NoLogTimes -UTF8Output
环境变量 — 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
注1:在windows配置好iOS远程构建环境,也可以在windows上构建iOS版本 详见:在 Windows 上构建 iOS 版本
注2:Mac上cook失败,提示:CookResults: Error: Package Native Shader Library failed for MacNoEditor. 可通过关掉Project Settings – Packing – Shared Material Native Library来解决
④ 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某些头文件
原因是不同编译器递归展开头文件规则存在差别
Post Link: UE4游戏开发基础命令