There are multiple ways to reduce the build size. But on mobile platforms, this issue is most acute. I will show you how I managed to reduce the size of my Android game from 150MB to 50MB.
There are many switches in the project settings that will help reduce the build size.
The first thing you can do is set “Build Configuration” to “Shipping” and enable “For distribution”:
You can exclude some unused editor assets and compress the required ones like this:
You can also enable sharing material shader code and use of shared material native libraries, which will slightly reduce the size:
If you are not using moving point lights, set “Max Movable Point Lights” to 0. This will slightly reduce the size of the shaders and hence the build size:
It is likely that your project contains unused plugins that are enabled by default. I recommend going to the Plugins tab and disable the ones you don’t need. It depends on each project, but I came up with the following list:
- Android media player
- Android movie player
- Apple movie player
- Windows Movie player
- WMF media player
- Kdevelop Integration
- Cable component
- AVF media player
- Audio capture
- Archvis character
Excluding packaged assets
You can also remove unused assets that are packaged with your game but are never used. The following example is relevant for the Win64 platform.
First, you need to figure out which specific assets you need to exclude. To do this, you will need to open the
main.obb.png file as an archive located in the “assets” folder inside your game’s pak file.
To unpack the .pak file and get to the
main.obb.png file, open the console in the
Engine/Binaries/Win64 folder and write the following command:
UnrealPak.exe [PathToPakFile].pak -extract [PathToExtractPakFile]
After that you can walk through the extracted folders/files and select what is not used in your game.
Once you have decided which resources are not required in your game, you need to open (or create) the
PakBlacklist-Shipping.txt file in the
[PROJECT_NAME]/Build/Android directory and specify the folders and files that need to be excluded when building the project. In my case, I got the following list:
../../../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
Disabling engine modules
If you are still not satisfied with the build size, there is another option - to rebuild the engine with disabling unused but heavy modules, which are also included when the project is packaged.
To do this, download the engine sources, generate the project files and open the Unreal Engine solution through the IDE.
Then open the UnrealGame.Target.cs file in the
Source directory and set the following variables:
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;
At the end, you only need to rebuild the engine and your project for the target platform.