在我的的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表示为服务器版本