Search Unity

Question How to reduce the built size for an empty project

Discussion in 'Editor & General Support' started by Capricornum, Feb 8, 2021.

  1. Capricornum

    Capricornum

    Joined:
    Feb 1, 2018
    Posts:
    22
    Dear Community,

    When I create a new 2D template project in Unity and deploy a build for MacOS, that build is 60mb large.

    I have spent the last 2 days researching ways to decrease the size of Unity builds. I have found a lot of information on how to compress textures, sprites, sounds and other assets but no (up to date) information on how to decrease the overhead that comes with Unity itself. I think 60mb is very big for nothing in it.

    Using the Compression options LZ4 and LZ4HC specified in the Build Settings Window had no effect.
    Deleting all unused packages (like Timeline and TextMeshPro) had no effect. So I am out of ideas.

    I would greatly appreciate some help with my problem. Is it possible at all, to decrease that empty project build size? Where do all those megabytes come from?

    Thank you
     
  2. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    Capricornum likes this.
  3. Moonjump

    Moonjump

    Joined:
    Apr 15, 2010
    Posts:
    2,572
    What version of Unity are you using? That make a difference.

    Removing packages in the Package Manager can make a difference, but you say you removed all unused packages. What packages are you using in an empty project?

    Compression options will make no difference until you add some textures and set the compression on them.
     
    Capricornum likes this.
  4. Capricornum

    Capricornum

    Joined:
    Feb 1, 2018
    Posts:
    22
    Thank you for the input. I will have a look at that.
     
    Joe-Censored likes this.
  5. Capricornum

    Capricornum

    Joined:
    Feb 1, 2018
    Posts:
    22
    Hello Moonjump
    I am using Unity 2020.1.11. I never tried using a different version. Thats a good idea.
    I removed all packages except 'Unity UI', '2D Sprite' and 'Visual Studio Editor'. Those are the ones I would be using, if I actually continued. After removing about 10 other packages the difference was 1mb.
    I see, that makes sense.
    Do you know of any other features under the hood, that I might be able to disable/remove/exclude from the build?
    Thank you.
     
  6. Moonjump

    Moonjump

    Joined:
    Apr 15, 2010
    Posts:
    2,572
    In the Package Manager window, there is a drop down (top-left) that says All Packages. Select Built-in Packages, and you will get a list that isn't included in All (odd isn't it!). There are a few there that should save more than 1MB.

    In Project Settings, go to Player, Other Settings.
    In Optimisation, change Managed Stripping Level to High. Plus change Preloaded Assets size to zero.
    In Configuration, see what happens if you change the Scripting Backend and/or Api Compatibility Level.

    In Project Settings, go to Graphics.
    Remove any Always Included Shaders and Preloaded Shaders.
    In Built-in Shader Settings, change to No Support for any you will not use.
    Deselect everything in Shader Stripping.

    My current project is on iOS, which is usually one of the largest builds. It is a complete game and includes 2 external SDKs. It is 48MB on the App Store, so I am surprised at the size you get with an empty project.
     
    Last edited: Feb 9, 2021
    MattDavis, Capricornum and JamesArndt like this.
  7. Capricornum

    Capricornum

    Joined:
    Feb 1, 2018
    Posts:
    22
    Wow, that is a great list. Thank you! I never knew about those built in Packages. I am looking forward to experimenting with them and stripping those I don't need.
    I will also look at the Scripting Backend and Api Compatibility Level.

    Unfortunately I don't know anything about shaders. I looked at Unity's Documentation about them. However I have no idea which shaders I am using, which ones are useful for what or which ones I can change to 'No Support' like you suggested. Is there a way for me to find out which shaders I am using or might be important for me?

    Thats the goal I am reaching for here. I'm glad it's working out for you. Whats the game called?
     
  8. Capricornum

    Capricornum

    Joined:
    Feb 1, 2018
    Posts:
    22
    I deleted unnecessary packages within my project: Decrease of 1.6mb.
    I deleted unnecessary packages within the 'all packages' tab: No change.
    I removed all 'always included shaders' and selected 'No Support' for all Built-In Shader Settings: Decrease of 0.4mb
    I deselected everything in Shader Stripping: No change.
    I tried .net 4.x as the Api Compatibility Level: Increase of 0.3mb.
    I tried IL2CPP as the Scripting Backend with the .net 2.0 Api Compatibility: Decrease of 0.2mb and an additional folder with 138mb was saved to disk. The folder is named: 'BackUpThisFolder_ButDontShipItWithYourGame'.

    Now here it comes: I changed Managed Stripping Level to high: Decrease of 16mb!!

    So thank you Moonjump. My empty project is still as large as your finished game on AppStore but at least I managed to decrease the size to 2/3s.
    I will keep looking in my setting for other options to lose some weight.
     
  9. Havokki

    Havokki

    Joined:
    Jun 28, 2015
    Posts:
    118
    In case you're not familiar with code stripping, the manual has some more info on that:
    https://docs.unity3d.com/Manual/ManagedCodeStripping.html

    Just in case you get the "called non-existent method" error, which means one of the methods you were using was stripped from the build. The manual also lists ways to fix it.
     
    Capricornum likes this.
  10. Moonjump

    Moonjump

    Joined:
    Apr 15, 2010
    Posts:
    2,572
    The game is called Jigscore, but it is only on a limited soft launch at the moment, so only available in a couple of countries. Hopefully it will be fully released soon.
     
    Capricornum likes this.
  11. Capricornum

    Capricornum

    Joined:
    Feb 1, 2018
    Posts:
    22
    Thank you. Very considerate to inform me ahead of time. I will remember this just in case.
     
    Havokki likes this.
  12. Capricornum

    Capricornum

    Joined:
    Feb 1, 2018
    Posts:
    22
    Nice. Good luck!
     
    Moonjump likes this.
  13. KillDashNine

    KillDashNine

    Joined:
    Apr 19, 2020
    Posts:
    453
    I suggest you look at your built game folders. For myself (PC), UnityPlayer.dll is around 27MB. Then there's the Data folder where you'll find your scenes and resources. Under that there is Managed where you'll find a bunch of DLLs that are managed plugins. If you want to really go naked then I think you can find stuff there that can be stripped away, such as any Unity Editor DLLs.
     
    Capricornum likes this.
  14. Capricornum

    Capricornum

    Joined:
    Feb 1, 2018
    Posts:
    22
    Thanks for the tip. I will take a look at that. See what I can remove without crashing my game:)
     
  15. DankalApps

    DankalApps

    Joined:
    Mar 8, 2023
    Posts:
    17
    I am trying to minimize Android build. Can't get below 40MB (installation size)

    For testing purposes:
    - created empty 2D project, using newest editor 2021.3.20
    - removed all packages and features (2d, meshpro, etc.)
    - disabled **all** Built-in packages
    - changed Managed Stripping level to "High" ("low" gives similar results, so better stick to it)

    After this, I take a look at `AppBuild.apk` and there are many .dlls that are not needed, e.g.:
    - UnityEngine.VRMudule.dll,
    - UnityEngine.AIModule.dll
    - UnityEngine.VideModule.dll
    Those are just examples, they are not even that large. Just using it as a proof that things not needed in build are still getting into it.

    What is taking most space in the apk is in these 3 folders:
    EmptyProjectApkAnalysis.png

    This results in:
    - .apk size: 14.5MB large
    - installation size: 40MB on the android device.

    What else can I do so Unity removes all not needed stuff from the build?