文章

在虚幻引擎中减少 Android 或 iOS 游戏的构建大小

项目设置

  • 设置Build ConfigurationShipping启用For distribution

  • 排除一些未使用的编辑器资产并像这样压缩所需的资产:

  • 启用共享材质着色器代码和使用共享材质本机库,这将稍微减小大小,但是会导致运行时加载的效率

  • 如果不使用移动点光源,请将“Max Movable Point Lights”设置为 0。这将略微减小着色器的大小,从而减小构建大小:

Disabling plugins

的项目可能包含默认启用的未使用插件:

  • Android media player
  • Android movie player
  • Apple movie player
  • CharacterAI
  • OculusVR
  • Windows Movie player
  • WMF media player
  • SteamVR
  • Kdevelop Integration
  • Cable component
  • AVF media player
  • Audio capture
  • Archvis character

Excluding packaged assets

还可以删除游戏中打包但从未使用过的未使用资产。以下示例与 Win64 平台相关。

首先,需要确定需要排除哪些特定资产。为此,需要打开main.obb.png游戏 pak 文件内“assets”文件夹中的存档文件。

要解压.pak文件并获取main.obb.png文件,请在文件夹中打开控制台Engine/Binaries/Win64并编写以下命令:

1
UnrealPak.exe [PathToPakFile].pak -extract [PathToExtractPakFile]

之后,可以遍历提取的文件夹/文件并选择的游戏中未使用的内容。

一旦确定了游戏中不需要哪些资源,在 [PROJECT_NAME]/Build/Android 打开(或创建)PakBlacklist-Shipping.txt,并指定构建项目时需要排除的文件夹和文件。

例如:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
../../../Engine/Plugins/Blendables/
../../../Engine/Plugins/Editor/
../../../Engine/Plugins/Enterprise/
../../../[PROJECT_NAME]/AssetRegistry.bin
../../../Engine/Content/ArtTools/
../../../Engine/Content/EngineFonts/Faces/
../../../Engine/Content/Internationalization/icudt64l/coll/
../../../Engine/Content/Internationalization/icudt64l/translit/
../../../Engine/Content/Internationalization/icudt64l/lang/
../../../Engine/Content/Internationalization/icudt64l/unit/
../../../Engine/Content/Internationalization/icudt64l/zone/
../../../Engine/Content/Internationalization/icudt64l/region/
../../../Engine/Content/Localization/
../../../Engine/Content/Maps/
../../../Engine/Content/MobileResources/
../../../Engine/Content/SlateDebug/
../../../Engine/Content/Tutorial/
../../../Engine/Content/Slate/Fonts/
../../../Engine/Content/Slate/Testing/
../../../Engine/Content/Slate/Tutorials/
../../../Engine/Content/Slate/Icons/
../../../Engine/Content/Slate/CrashTracker/
../../../Engine/Content/Slate/Old/
../../../Engine/Content/Slate/Docking/
../../../Engine/Content/Slate/Common/
../../../Engine/Plugins/Runtime/LeapMotionController/
../../../Engine/Plugins/Editor/SpeedTreeImporter/Content/SpeedTree9/game_wind_noise.ubulk

禁用引擎模块

如果仍然对构建大小不满意,还有另一种选择 - 通过禁用未使用但很重的模块来重建引擎,这些模块也包含在项目打包时。

为此,请下载引擎源代码、生成项目文件并通过 IDE 打开虚幻引擎解决方案。

然后打开目录下的 UnrealGame.Target.cs 文件,设置如下变量:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
bCompileAPEX = false;
bCompileICU = false;
bBuildDeveloperTools = true;
bCompileRecast = false;
bCompileSpeedTree = false;
bCompileForSize = true;
bCompileCEF3 = false;
bCompileFreeType = false;
bIWYU = true;
bUsesSlate = false;
bCompileChaos = false;
bUseChaos = false;
bUseChaosChecked = false;
bUseChaosMemoryTracking = false;
bCompilePhysX = false;
bCompileNvCloth = false;
bCompileRecast = false;
bCompileNavmeshSegmentLinks = false;
bCompileNavmeshClusterLinks = false;
bUseDebugLiveCodingConsole = false;
bUseLoggingInShipping = false;
bLoggingToMemoryEnabled = false;
bUseLauncherChecks = false;
bEnforceIWYU = true;

最后,只需要为目标平台重建引擎和的项目,仅此而已。

本文由作者按照 CC BY 4.0 进行授权