UE4游戏开发基础命令

在个人的Unrealengine账户中关联自己的GitHub账户成功之后,就可以访问UE4引擎的源码了。

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

克隆成功后,执行Setup.bat拉取并安装外部依赖文件(第三方库、资源包、示例工程等),最后调用UnrealVersionSelector添加引擎到注册表并在资源管理器中添加引擎快捷菜单功能

"%EngineDir%EngineBinariesWin64UnrealVersionSelector-Win64-Shipping.exe" /register

若需要设置代理可以传入相应参数来执行Setup.bat脚本 // Setup.bat会调用EngineBinariesDotNETGitDependencies.exe工具来获取依赖文件

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

注:如果是UE4.22版本,需要安装.net framework 4.6.2,安装完后在控制面板卸载列表中会有如下软件列表:

执行GenerateProjectFiles.bat生成UE4相关工程,生成的vs工程文件在EngineIntermediateProjectFiles目录中

双击UE4.sln,开始编译相关工具和引擎  // 编译的中间文件生成在EngineSourceEngineIntermediateBuild目录中

编译UnrealBuildTool

"C:WindowsMicrosoft.NETFramework64v4.0.30319msbuild.exe" "%EngineDir%EngineSourceProgramsUnrealBuildToolUnrealBuildTool.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%EngineBinariesDotNETUnrealBuildTool.exe" ShaderCompileWorker Win64 Development -waitmutex -FromMsBuild -DEPLOY  // Windows下编译ShaderCompileWorker

"%EngineDir%EngineBinariesDotNETUnrealBuildTool.exe" UnrealLightmass Win64 Development -waitmutex -FromMsBuild -DEPLOY  // Windows下编译UnrealLightmass

"%EngineDir%EngineBinariesDotNETUnrealBuildTool.exe" UnrealIdentifierRegister Win64 Development -waitmutex -FromMsBuild -DEPLOY  // Windows下编译UnrealIdentifierRegister

"%EngineDir%EngineBinariesDotNETUnrealBuildTool.exe" UnrealVersionSelector Win64 Development -waitmutex -FromMsBuild -DEPLOY  // Windows下编译UnrealVersionSelector

mono $EngineDir/Engine/Binaries/DotNET/UnrealBuildTool.exe ShaderCompileWorker Mac Development  // Mac下编译ShaderCompileWorker

使用UnrealVersionSelector添加引擎到注册表并在资源管理器上下文菜单中添加引擎快捷功能

"%EngineDir%EngineBinariesDotNETUnrealVersionSelector.exe" /register

1. 对uproject文件进行右键菜单注册

2. 注册uproject文件所用的引擎路径

编译引擎和项目

编译Development版本的UE4引擎  // 会在%EngineDir%BinariesWin64和%EngineDir%Plugins*···*BinariesWin64目录中生成引擎UE4Editor.exe、核心dll模块和引擎插件dll

"%EngineDir%EngineBinariesDotNETUnrealBuildTool.exe" UE4Editor Win64 Development -waitmutex -FromMsBuild -DEPLOY

生成项目MyGame的vs项目工程文件  // 工程文件会生成到"%GameDir%IntermediateProjectFiles"目录中

"%EngineDir%EngineBinariesWin64UnrealVersionSelector.exe" /projectfiles "%GameDir%MyGame.uproject"   //windows下

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

编译项目MyGame的Development Editor版本  // 会在%GameDir%BinariesWin64和%GameDir%Plugins*···*BinariesWin64目录中生成项目dll和项目插件dll

"%EngineDir%EngineBinariesDotNETUnrealBuildTool.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%EngineBinariesDotNETUnrealBuildTool.exe"  MyGameEditor Win64 Development "%GameDir%MyGame.uproject" -singlefile="%GameDir%SourceMyGameMyGameCharacter.cpp" -WaitMutex -FromMsBuild -DEPLOY

编译单个模块

"%EngineDir%EngineBinariesDotNETUnrealBuildTool.exe" -Module=MyGame Win64 Development -TargetType=Editor -Project="%GameDir%MyGame.uproject" -canskiplink "%GameDir%MyGame.uproject"

编译单个引擎模块

"%EngineDir%EngineBinariesDotNETUnrealBuildTool.exe" -Module=Engine Win64 Development -TargetType=Editor -Project="%GameDir%MyGame.uproject" -canskiplink -nosharedpch "%GameDir%MyGame.uproject"

编译多个模块 

"%EngineDir%EngineBinariesDotNETUnrealBuildTool.exe" -Module=MyCommon -Module=MyGame Win64 Development -TargetType=Editor -Project="%GameDir%MyGame.uproject" -canskiplink "%GameDir%MyGame.uproject" 

编译项目MyGame的客户端版本

"%EngineDir%EngineBinariesWin64UnrealVersionSelector.exe" MyGame Win64 Development -Project="%GameDir%MyGame.uproject"

编译项目MyGame的Linux Server版本

mono "%EngineDir%EngineBinariesDotNETUnrealBuildTool.exe" MyGameServer Linux Development -Project="%GameDir%MyGame.uproject"

一些log

UnrealHeaderTool:UnrealEngineEngineProgramsUnrealHeaderToolSavedLogsUnrealHeaderTool.log

UnrealBuildTool:UnrealEngineEngineProgramsUnrealBuildToolLog.txt

UAT:UnrealEngineEngineProgramsAutomationToolSavedLogsLog.txt

一些技巧

(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)IncredBuildxgConsole.exe改名

(5)如果只是想禁用shader编译的IncredBuild的加速,可在EngineConfigConsoleVariables.ini中打开r.XGEShaderCompile = 0

(6)从vs直接运行或调试运行UE时,不要进行任何编译行为

(7)UnrealVS扩展中文

右键Visual Studio工具栏区域,弹出快捷菜单,勾选显示UnrealVS工具栏

安装文件在:EngineExtrasUnrealVS

代码在:EngineSourceProgramsUnrealVS

提供了如下功能:

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等)

运行EngineExtrasVisualStudioDebuggingInstallVisualizers.bat(支持vs2012、vs2013、vs2015)进行安装

对于vs2017等更高版本,可以手动将EngineExtrasVisualStudioDebuggingUE4.natvis拷贝到%USERPROFILE%DocumentsVisual Studio 2017Visualizers目录中进行手动安装

安装完成后,重启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自动完成,来插入模板代码

配置方法:拷贝EngineExtrasVisualStudioSnippets中所有的snippet文件到C:Users<user>DocumentsVisual Studio 2017Code SnippetsVisual 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%EngineBuildBatchFilesRunUAT.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%EngineBuildBatchFilesRunUAT.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:NVPACKandroid-sdk-windows
ANDROID_NDK_ROOT    E:NVPACKandroid-ndk-r14b
ANT_HOME     E:NVPACKapache-ant-1.8.2
GRADLE_HOME    E:NVPACKgradle-2.9
JAVA_HOME    E:NVPACKjdk1.8.0_77
NDK_ROOT    E:NVPACKandroid-ndk-r14b
NDKROOT    E:NVPACKandroid-ndk-r14b
NVPACK_NDK_TOOL_VERSION    4.9
NVPACK_NDK_VERSION    android-ndk-r14b
NVPACK_ROOT    E:\NVPACK
Path    E:NVPACKgradle-2.9in;E:NVPACKapache-ant-1.8.2in;E:NVPACKjdk1.8.0_77in;E:NVPACKandroid-ndk-r14b;E:NVPACKandroid-sdk-windowsextrasandroidsupport;E:NVPACKandroid-sdk-windowsuild-tools;E:NVPACKandroid-sdk-windowsplatform-tools;E:NVPACKandroid-sdk-windows	ools;

注:若想升级ndk,可从这儿下载,解压后放到E:NVPACK目录中,并更新NDK_ROOT、NDKROOT及Path环境变量中的路径即可

在项目设置 -- Platforms -- Android页面中,点击Accept SDK License同意一下   注:会在E:NVPACKandroid-sdk-windowslicenses下生成一个android-sdk-license文件

C:Users<用户名>.gradle目录、C:Users<用户名>.android目录

配置gradle的代理(所在文件:C:Users<用户名>.gradlegradle.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%SavedCooked

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

其他

清理Development版本的UE4引擎

"%EngineDir%EngineBuildBatchFilesClean.bat" UE4Editor Win64 Development -waitmutex

清理Development版本的MyGame项目

"%EngineDir%EngineBuildBatchFilesClean.bat" MyGameEditor Win64 Development "%GameDir%MyGame.uproject" -waitmutex

为MyGame项目的TestMap_Main地图构建光照

"%EngineDir%EngineBuildBatchFilesRunUAT.bat" RebuildLightmaps -project=%GameDir%MyGame.uproject -MapsToRebuildLightMaps=TestMap_Main

在windows上重新打包和重签名,生成ipa文件  注:ipa文件生成在%GameDir%BinariesIOSMyGame.ipa

"%EngineDir%EngineBinariesDotNETIOSIPhonePackager.exe" RepackageFromStage "%GameDir%MyGame.uproject" -config Development -schemename MyGame -schemeconfig "Development" -sign -codebased -stagedir "%GameDir%SavedStagedBuildsIOS" -project "%GameDir%MyGame.uproject" -provision "DGame.mobileprovision" -certificate "iPhone Developer: cert RDM (CFG5EWN5ME)"

找不到XINPUT1_3.dll

安装引擎目录下EngineExtrasRedisten-usUE4PrereqSetup_x64.exe

关于解决方案的Configuration

 

1. Debug 游戏模块和引擎模块均开启调试模式

2. DebugGame  游戏模块开启调试模式,引擎模板开启优化

3. Development  游戏模块和引擎模块均开启优化

4. Shipping 发行版本(会去掉所有编辑器功能、stat统计以及GM命令等)游戏模块和引擎模块均开启优化

5. 带Editor表示为编辑器版本(含有很多编辑器相关的功能)

6. 都不带表示为客户端版本

7. 带Server表示为服务器版本

在windows下编译通过,而在其他Linux、Android、iOS等平台编译不过的一些情况:

1. 斜杠问题

如:#include "MiscFileHelper.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某些头文件

原因是不同编译器递归展开头文件规则存在差别

原文地址:https://www.cnblogs.com/kekec/p/8684068.html