ue4 命令行编译 烘焙 打包 存档

本文详细介绍如何使用Unreal Engine 4 (UE4)的命令行工具BuildCookRun来打包游戏,包括编译、烹饪资源、阶段化、打包和归档等步骤。提供了针对不同平台如Windows、Android和iOS的特定参数,以及如何处理pak文件、加密和调试信息等内容。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

首先是官方wiki的说明

How to package your game with commands

Jump to: navigation, search

Template:Rating This aims to be a quick guide on how to package and distribute your game.

Some points:

  • If you use unreferenced blueprints/objects, you should add them a) using command line or b) by creating a level with all the objects you need to publish in your game (not recomended)

  • Cooking is the proccess of removing unwanted files from your final build

  • You can choose to Pak (like zip) all your content into a single file

  • If you are building a dedicated server, you need to have the compiled version of Unreal or will not work.

  • You will find the RunUAT at UnrealEngine/Engine/Build/BatchFiles

  • Add the command -build if you're using Source Version from Github

  • If the -allmaps flag is used, [AllMaps] with valid +Map=\Game\Maps\Map.umap syntax should be added to DefaultEditor.ini

  • Specific maps can be built (must remove -allmaps flag) using the -maps=Map1+Map2+Map3

Compiling the client (With PAK files):

RunUAT BuildCookRun -project="full_project_path_and_project_name.uproject" -noP4 -platform=Win64 -clientconfig=Development -serverconfig=Development -cook -allmaps -build -stage -pak -archive -archivedirectory="Output Directory"

Cooking the client (With PAK files):

RunUAT BuildCookRun -project="full_project_path_and_project_name.uproject" -noP4 -platform=Win64 -clientconfig=Development -serverconfig=Development -cook -allmaps -NoCompile -stage -pak -archive -archivedirectory="Output Directory"

Compiling the dedicated server (With PAK files):

RunUAT BuildCookRun -project="full_project_path_and_project_name.uproject" -noP4 -platform=Win64 -clientconfig=Development -serverconfig=Development -cook -server -serverplatform=Win64 -noclient -build -stage -pak -archive -archivedirectory="Output Directory"

Cooking the dedicated server (With PAK files):

RunUAT BuildCookRun -project="full_project_path_and_project_name.uproject" -noP4 -platform=Win64 -clientconfig=Development -serverconfig=Development -cook -server -serverplatform=Win64 -noclient -NoCompile -stage -pak -archive -archivedirectory="Output Directory"

 

 

 

BuildCookRun 参数:

常用参数如下,详细参数见源文件 Engine\Source\Programs\AutomationTool\AutomationUtils\ProjectParams.cs,注意有些参数不能同时指定,具体见 ValidateAndLog 函数里的参数检查规则。Engine\Source\Programs\AutomationTool\AutomationUtils\Automation.cs 有一些全局参数定义

整体打包过程如下: Build -> Cook-> Stage -> Package -> Archive

基本设置

 

-project=Path

项目路径(必填)

-project=D:\Projects\MyProject.uproject

-project="F:/Unreal Projects/testChunk/testChunk.uproject"

-noP4(通常都带这个)

-nop4禁用Perforce功能(如果未在构建计算机上运行,则为默认值)

-targetplatform(或者-Platform)=PlatformName

目标平台,定义在枚举 UnrealTargetPlatform 中,包含 Win32/Win64/Mac/XboxOne/PS4/IOS/Android/HTML5/Linux/AllDesktop/TVOS/Switch

 

-targetplatform=Android

-pak

生成一个pak文件, 是否将资源文件打包到pak中,但是并不是说不指定这个命令行就不用pak,有些平台只能用pak(比如Android打包成apk),不管有没有这个参数,具体见各个平台对

-createreleaseversion=3.0

创建release版本3.0,版本信息用于dlc/补丁

-basedonreleaseversion=2.0

基于的版本版本信息用于dlc/补丁

-generatepatch

生成补丁(应不与createreleaseversion 一起使用。

-UTF8Output

log,控制台窗口等输出使用UTF8编码

-p4

-p4启用Perforce功能(如果在构建计算机上运行,则为默认值)

-servertargetplatform (或者-ServerPlatform)=PlatformName

Dedicated Server 目标平台,定义同上

 

 

-clean

(在构建之前擦除intermediate文件夹)重新完整构建

-signpak=keys

sign the generated pak file with the specified key, i.e.

                                       -signpak=C:\Encryption.keys. Also implies -signedpak.

-SignPak=C:\Encryption.keys 或者 -signpak=0x…..: 指定加密pak文件密钥内容或者密钥文件路径,密钥内容以 0x 开头,同时 -SignedPak 参数也生效

-signed

游戏应该使用加密的pak文件

-skippak

不生成pak,使用上一次的构建的pak文件,包含-Pak

-CrashReporter

构建CrashReporter

Build相关参数

 

-build

执行编译过程

-clientconfig=Development

客户端编译的构建配置DebugGame/Development/Shipping

-serverconfig=Development

服务器编译的构建配置DebugGame/Development/Shipping

-NoCompile

跳过编译(纯蓝图项目)

-SkipBuildClient

不编译客户端

-SkipBuildEditor

不编译编辑器

-noxge

不执行并行编译

-ForceDebugInfo

在非Debug版本中加入调试信息Forces debug info even in development builds

Cook 相关参数

 

-cook,

使用Cooked资源

-CookFlavor=

-CookFlavor=Multi/ATC/DXT/ETC1/ETC2/PVRTC/ASTC: 指定Android Cook格式

-MapsToCook=

-MapsToCook=map1+map2+map3: 指定要cook的关卡,多个之间用+号连接

-Compressed

: 压缩

-UnversionedCookedContent

不包含版本号

-SkipCookingEditorContent

 在烘焙时跳过/Engine/Editor文件夹中的内容(Skips content under /Engine/Editor when cooking)

不cook引擎编辑器使用到的资源

-CookAll

烘培content文件夹中的所有东西

-CookMapsOnly

只cook关卡和关卡引用到的资源,只会在同时指定了-CookAll时生效

-manifests

在cooking data时生成 流安装(streaming install) manifests

-createchunkinstall

在cooking data时生成流安装(streaming install)数据, 需要 -stage和-manifests

-skipcook

跳过cook阶段,使用上一次Cook好的资源,同时包含了 -Cook 参数

-CookOutputDir=path

-CookOutputDir=C:\cooked: 指定cook结果保存目录,默认在Project/Saved/Cooked(使用UAT cook)和Project/Saved/EditorCooked(使用editor cook)

-CookInEditor

使用editor进行cook而不是UAT

-ue4exe=ExecutableName

-ue4exe="D:\Program Files\Epic Games\UE_4.22\Engine\Binaries\Win64\UE4Editor-Cmd.exe"

 

指定ue4 Editor 的可执行文件路径

-IgnoreCookErrors

忽略cook 错误

-CookPartialgc

 cook阶段磁盘空间不够不要清理所有资源

-AdditionalCookerOptions

-AdditionalCookerOptions=xxx: 额外的传给cooker进程的命令行

-FastCook

开启FastCook,如果项目支持的话

-NumCookersToSpawn

指定cooker进程的数量

-iterativecooking(或者-iterate)

迭代烘培

-EncryptIniFiles:

加密ini文件,只在指定了加密密钥和使用pak文件时候有效

-EncryptEverything

加密所有的文件,只在指定了加密密钥和使用pak文件时候有效

-EncryptPakIndex

加密pak索引,只在指定了加密密钥和使用pak文件时候有效

Stage相关参数

 

-stage

保存构建过程中的中间结果

-stagingdirectory=Path

-StagingDirectory=C:\xxxx: 构建过程中中间结果保存目录,默认在ProjectPath\Saved\StagedBuilds

-skipstage

不保存构造过程中的中间结果,使用上一次的结果,这个命令行同时包含了 -Stage

-nodebuginfo

不拷贝调试信息文件到Stage目录,也就是最终打出来的包中不包含调试信息

-nocleanstage

 新构建不会清理之前StagingDirectory中的文件, 如果指定了-clean则一定会清理掉

-StageCommandline=

-StageCommandline=xxxx: 放在UE4CommandLine.txt中的一系列命令行,打出来的包在运行时会从这个文件中读取命令行并执行

Package相关参数

 

-package

执行打包  Andorid->apk, iOS->ipa

-distribution

打的包是发布版本,在Android和iOS上会禁掉Debugable属性

-prereqs

指定打包游戏是否包含先决条件的安装文件(例如支持平台上的操作系统可发布组件)

-applocaldir

指定是否在游戏可执行文件中包含先決条件。

-AdditionalPackageOptions

给平台打包器的额外参数(extra options to pass to the platform's packager)

Archive相关参数

 

-archive

将构建结果归档

-archivedirectory=Path

归档目录,默认为ProjectPath\ArchivedBuilds

-bundlename

部署到移动设备上时使用的使用的绑定名称 string to use as the bundle name when deploying to mobile device

-createappbundle

When archiving for Mac, set this to true to package it in a .app bundle instead

当目标平台是Mac时,指定这个参数可以归档成一个 .app 文件而不是一堆散文件

Run相关参数

 

-run

构建之后运行游戏

-cookonthefly

使用在服务器上提供的cook过的资源进行游戏

-Cookontheflystreaming

同上,但是不缓存资源到本地

-fileserver

使用UnrealFileServer上的cook过的资源数据

-dedicatedserver(或者-server)

构建 cook 并运行客户端和服务器

-client

build, cook and run a client and a server, uses client target configuration

-noclient

do not run the client, just run the server

-logwindow

为客户端创建log窗口

-map

指定游戏运行的关卡

-device

Devices to run the game on

-serverdevice

Device to run the server on

-skipserver

Skip starting the server

-AdditionalServerMapParams

Additional server map params, i.e ?param=value

-numclients=n

Start extra clients, n should be 2 or more

-addcmdline

Additional command line arguments for the program

-servercmdline

Additional command line arguments for the program

-clientcmdline

Override command line arguments to pass to the client

Deploy相关参数

 

-deploy

部署

-DeployFolder=

部署路径

Other

 

-destsample

Destination Sample name(目标样本名称)

-foreigndest

Foreign Destination

-foreign

Generate a foreign uproject from blankproject and use that

-foreigncode

Generate a foreign code uproject from platformergame and use that

-skipcookonthefly

在cookonthefly构建中,仅用于将信息传递给包装步骤

-unattended

assumes no operator is present, always terminates without waiting for something.

-prepak

试图避免cooking,而是从网络中提取pak文件,包含了-pak和-skipcook。

-separatedebuginfo

output debug info to a separate directory

-MapFile

generates a *.map file

-Prebuilt

this is a prebuilt cooked and packaged build

-getfile

download file from target after successful run

-IgnoreLightMapErrors

是否应将Light Map错误视为关键错误

-archivemetadata

Archive extra metadata files in addition to the build (e.g. build.properties)

存档除了构建之外的额外元数据文件(例如build.properties)

-cmdline

命令行写入 stage 文件夹中的  UE4CommandLine.txt

-nullrhi

add -nullrhi to the client commandlines

-fakeclient

adds ?fake to the server URL

-editortest

rather than running a client, run the editor instead

-RunAutomationTests

when running -editortest or a client, run all automation tests, not compatible with -server

-Crash=index

when running -editortest or a client, adds commands like debug crash, debug rendercrash, etc based on index

-deviceuser

Linux username for unattended key genereation

-devicepass

Linux password

-RunTimeoutSeconds

timeout to wait after we lunch the game

-SpecifiedArchitecture

Determine a specific Minimum OS

-UbtArgs

extra options to pass to ubt

-MapsToRebuildLightMaps

List of maps that need light maps rebuilding

-MapsToRebuildHLODMaps

List of maps that need HLOD rebuilding

-ForceMonolithic

Toggle to combined the result into one executable

-ForceNonUnity

Toggle to disable the unity build system

-ForceUnity

Toggle to force enable the unity build system

-Licensee

If set, this build is being compiled by a licensee

-NoSign

Skips signing of code/content files.

 

 

 

 

### 如何在Unreal Engine 5中将项目打包成可执行文件 在 Unreal Engine 5 中,将项目打包为可执行文件是一个相对简单的过程。以下是关于如何完成此操作的具体说明: #### 使用 Unreal Editor 进行打包 通过 Unreal Editor 的图形界面可以轻松实现项目的打包过程。 1. **打开目标平台的配置选项** 在 Unreal Editor 中,点击顶部菜单栏中的 `File` -> `Package Project` 来启动打包流程。这会弹出一个窗口,允许选择要导出的目标平台(例如 Windows、Mac 或 Linux)。对于大多数开发人员来说,Windows 平台是最常见的选择[^1]。 2. **设置构建参数** 当选择了目标平台之后,系统可能会提示进一步调整一些高级设置,比如是否启用调试信息或者优化编译选项等。这些都可以根据实际需求自定义设定。如果不确定具体数值,则保留默认值通常也是安全的选择[^2]。 3. **指定输出路径** 接下来需要指明最终生成的应用程序将会被放置在哪一目录下保存。建议选取易于访问的位置以便后续分发测试之用。 4. **开始打包进程** 完成了以上准备工作以后就可以正式启动打包命令了。整个过程中可能涉及大量数据处理以及代码编译工作,因此所需时间长短取决于计算机性能高低及项目规模大小不等。 #### 命令行方式下的自动化脚本支持 除了手动利用编辑器之外,还可以借助于命令行工具来进行更灵活高效的批量生产作业。这种方法特别适合那些希望集成 CI/CD 流程的企业级应用场合。 ```bash UE5_PATH\Engine\Build\BatchFiles\RunUAT.bat BuildCookRun -project="YourProject.uproject" -platform=Win64 -clientconfig=Shipping -cook -allmaps -build -stage -pak -archive -archivedirectory="OutputDirectory" ``` 上述脚本展示了如何通过批处理文件调用 UAT 工具链来完成一系列复杂任务的操作方法。其中各个参数的意义如下所示: - `-project`: 指定待处理的游戏工程文件名。 - `-platform`: 设定目标运行环境类别。 - `-clientconfig`: 控制客户端版本质量等级,默认推荐采用 Shipping 表示正式发布状态。 - `-cook`: 启动资源预烘焙阶段。 - `-allmaps`: 对全部地图场景均做相应转换处置。 - `-build`: 实施重新编译动作。 - `-stage`: 准备好部署素材集合体。 - `-pak`: 将资产压缩封装至 .pak 文件形式存储起来。 - `-archive`: 开启存档模式开关标志位。 - `-archivedirectory`: 明确指出最后成果物应该存放的确切地址位置[^1]. #### 注意事项 为了确保成功创建独立运行版别的软件产品,在实施之前还需要注意几个方面的问题: - 清理不必要的依赖项以减少体积占用; - 验证所有外部链接服务的有效性和兼容性状况; - 提前规划好数字版权保护机制以防非法复制传播行为发生; ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值