The game size is one of the key factors while developing games for mobile devices. Size factor can contribute to more user acquisition and can also affect performance. There are different ways of optimizing a game and its size with Unity. In this article, we will be taking a look at some of the major factors that help in the size optimization of a game. So we will be discussing:

  1. Cleaning up the project and removing unnecessary assets, models and scripts
  2. Removing built-in packages in your project that aren’t being used
  3. Importing images and compressing textures
  4. IL2CPP Compilation and ARMv7 vs ARM64 architecture
  5. Properly handling unity scenes and use of runtime instantiation

1. Cleaning up the project and removing unnecessary assets

The first thing above everything else that matters in your game size is the use of assets like images, sounds, scripts and prefabs you use for the development of your game. While in the development phase you might use many assets for your project which can be of no use later in the production, for eg: you might be using a Playerholder.png image in your development phase but later while you plan out for production you might have disabled that image’s game object in your project. So when you do this even though the specific picture isn’t visible anywhere in your game the unity compiler thinks that you are using the image even if it is disabled and compiles the asset into its shared assets. In order to avoid this, you should recheck and remove all the assets that aren’t used in your game. You can also check what assets are being compiled if you click on the 3 dots in your unity console window, doing this will open your editor.log. You can then open the editor log in any text editor and find (“Build Report”), which will provide you with all details of what assets are being compiled in your build with Unity.

Build report looks like this
Opening editor log from console

2. Removing built-in packages, not in use

When you create your project in unity for the first the engine might import some extra packages in your project as default that might be of no use for you. You can remove those packages, removing those packages might contribute a lot in lessening your build size. For eg: you create a game that has no use of 3D physics but you could have unknowingly imported it in your project so while you compile your build this specific 3D physics package might increase your build size by 2-3 MB. You can search for unused packages through your project’s package manager and you can also remove/disable them through the same package manager. [Package manager : Window > Package Manager > Built-In ]

Example of Package Manager

3. Importing images and compressing textures

While importing images or textures to your unity project always make sure to import the image with height/width having a multiple of 4, for eg: 128x128, 256x256. We need to do this because if the image’s height/width is a multiple of  4 the image cannot be crunch compressed or compressed to ETC2 format. You should also give priority to 9 slicing for most of the images throughout the game, doing this will save resources and most of the images used throughout the game will be in kilobytes. For bigger model textures you can change its max size from the image setting max size section. For compression, you can use the crunch compression value but that might not be very good for the original game quality in all the devices.

Texture change GIF

4. ARMv7 vs ARM64 architecture

You can also change your build architecture to ARMv7 in order to lower down your build size but this will make the app work with devices supporting ARMv7 architecture only, if you need your application to support both armv7 and ARM64 architecture you can create two builds with ARMv7 and ARM64 in this way when you upload the app in play store you can upload both of the builds and the store will download the app with architecture version of user’s device. You also need to set the managed stripping level to medium, this might also help in a part of size optimization.

5. Properly handling unity scenes and use of runtime instantiation

A unity scene is a level/environment system for your game, an unity scene is also a collection of objects and instances. While building unity also compiles all the scenes in your build settings to your output build, so unity scenes having fewer sizes can also help in size optimization. Unity scenes tend to increase size when you keep creating objects and instances of your scripts in the scene, for eg: when you have 1 button in your scene might be in 0.1kb size but when you have 100 buttons in your scene size might go up to 10kb, same goes with all the game objects you create, all the texts you add, all the terrains you add and so on can make the scene size go way higher. To solve that issues if possible you can generate all the extra stuff by just instantiating it in the game’s runtime. This will help the scene be of a lower size as the scene wouldn’t have to contain all the objects before being loaded in runtime.