- Home /
Does removing scenes from build settings reduce the file size of a game?
I have a project with quite a few assets, but it would be a pain to go through and figure out exactly which ones I need for my game to run. I've unchecked my testing and debug levels from the build settings but I don't know whether or not I should remove them entirely and whether that would make my game take less file space.
Answer by Bunny83 · Sep 07, 2020 at 08:05 AM
No, you don't have to remove your testing and debug scenes from the build settings. Unchecking should be enough so they are not shipped with the game. Actually if you look closely only the checked scenes get a build index. You can also verify this by checking which scenes are available in the SceneManager.
Unity be default only includes assets that are used somewhere, either directly in a scene or indirectly by something that is referenced from something in one of those scenes (like prefabs, materials, meshes, ...).
The only exceptions for this rule are any "Resources" folders in your project. Assets inside a Resources folder are always shipped with the game since they can be loaded through Resources.Load by their name, so Unity does not know which you might need or use. The second thing is the StreamingAssets folder. Anything you put into that folder will be shipped with your game "as it is". Unity will not import any assets from this folder. Unity just ship that folder with your build game. On most platforms this is an actual subfolder in your build directory. However on some platforms (like Android) the streaming assets are packed into the APK file. Lastly there are some settings panels in the PlayerSettings where you can reference certain assets. This could be a list of shaders, the application icon, splash screen assets, etc.
Apart from that nothing that isn't "used" / referenced from any scene, other included asset or from any settings panel will not be shipped with your game.
Note that this is only true for "assets". Scripts on the other hand are all included since the whole codebase is compiled into one or multiple assemblies which are shipped with your game. Code stripping might remove "some" things, but I wouldn't rely on that. Of course any editor code is not shipped with your game since editor scripts are compiled into a seperate assembly that is only used in the editor.
Thank you so much! I did not know that assets in the "Resources" folder are always used. I actually named my main folder without being aware of this property so it must have resulted in importing tons of unused assets! Super helpful answer!
Answer by Soareverix · Sep 14, 2020 at 11:19 PM
I found two errors in my game that were significantly increasing the size. One was that I had a folder named Resources with a bunch of prefabs in it. The second reason, however, was much more significant: while doing level design, I had duplicated my scene with a baked lightmap in it. Even though I'd deleted all of the static objects, the lightmap folder had also copied (in another folder) so that was why my game was taking up so much space. After resolving the lightmap issue, my game size dropped from 1.8 GB to ~400 MB. Massive improvement. Hope this helps someone!