Search Unity

  1. Unity 2019.1 is now released.
    Dismiss Notice

Ability to remove unused parts of the Unity emgine to make builds smaller.

Discussion in '5.3 Beta' started by giorgos_gs, Dec 6, 2015.

  1. giorgos_gs

    giorgos_gs

    Joined:
    Apr 23, 2014
    Posts:
    543
    Hi,

    When I bought Unity 5 I remember that it was advertised that it is in the roadmap the ability to remove unused parts of the engine to make the build, eg apks smaller. Eg if I make a simple 2d game, why pack the 3d engine or the huge 3d physics, lights etch. All these should be packed in pieces only if they are used in the project or at last we can have a choice to take out parts of the engine. I made a small app before some days, very simple with a few graphics and it packed 32mb in android and 64 in ios because of the 64bit code. This is just a waste of space.
     
  2. superpig

    superpig

    Quis aedificabit ipsos aedificatores? Unity Technologies

    Joined:
    Jan 16, 2011
    Posts:
    4,153
    This is called Engine Stripping, and we already do it for many parts of the engine when you build with the IL2CPP scripting backend. Check your Player Settings for both the Scripting Backend option, and, when IL2CPP is selected, the Strip Engine Code option.
     
    Meltdown likes this.
  3. giorgos_gs

    giorgos_gs

    Joined:
    Apr 23, 2014
    Posts:
    543
    What are the current strip level choices mean?
     
  4. superpig

    superpig

    Quis aedificabit ipsos aedificatores? Unity Technologies

    Joined:
    Jan 16, 2011
    Posts:
    4,153
    They relate to stripping of managed code, not engine code. Under IL2CPP, managed code is always maximally stripped.
     
  5. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    3,474
    Beware that this doesn't work with asset bundles - which kind of makes sense since there is no way for Unity to know what you will eventually put into asset bundles. Our project is almost 100% in bundles, so the stripping option will remove things like the particle system.

    Personally, I'd prefer a list of features to disable - as I know, for instance, we're never going to use certain features in our project and can safely strip them. Then I'd be able to use this feature to reduce our memory/download bloat.
     
  6. superpig

    superpig

    Quis aedificabit ipsos aedificatores? Unity Technologies

    Joined:
    Jan 16, 2011
    Posts:
    4,153
    You can work around the stripping problem for now by just including a scene in your build (which you never actually load) that has a particle system, or whatever other things you want to ensure don't get stripped.

    We're working on fixing this in the future so that the stripper knows about the engine subsystems that were used in asset bundles.
     
    10FingerArmy likes this.
  7. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    3,474
    How is that going to work though when the major use of asset bundles is to patch a game with new content without going through the submission of a new client?
     
  8. superpig

    superpig

    Quis aedificabit ipsos aedificatores? Unity Technologies

    Joined:
    Jan 16, 2011
    Posts:
    4,153
    Because, as you said, the major use of asset bundles is to provide new content - new data for systems that are already built into the game. Not whole new functionality that isn't in the base player build. (On iOS, at least, it'd actually be against the TOS to deliver new executable code in an AssetBundle).
     
  9. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    3,474
    Also, you should likely default this option to OFF until you figure out what to do about asset bundles - everyone who upgrades a project to a version which has this feature and uses asset bundles will immediately have to debug why their game doesn't work anymore - which is what I did.
     
  10. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    3,474
    Ok, let me use our game as an example; we run on iOS/Android/WebGL/etc. Because we run under webGL, we need the initial app size to be as small as possible. Thus, everything except the initial loading screen and error panel is inside an asset bundle. The app itself is just compiled code, two textures, and one UI screen - everything else is dynamically downloaded data. Yes, all the code is there, but it seems like you scan the data, not the code (that, or we're not referencing the ParticleSystem component anywhere in code).

    So, the current stripping option strips nearly the entire engine from the game, because our included scene doesn't use most of the engine.
     
  11. superpig

    superpig

    Quis aedificabit ipsos aedificatores? Unity Technologies

    Joined:
    Jan 16, 2011
    Posts:
    4,153
    Yes, as I said, the current stripping behaviour is going to be fixed in the future to account for data in your asset bundles. For now, the workaround is to include an instance of every engine component you want to use in the player build in an extra scene that you don't load.
     
  12. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    3,474
    So what your saying is that if I build the game and ship it to users with no particle effects the game or bundles, it's going to strip the particle system code. Then I add a particle system into an asset bundle after this build is made and ship it to the user without updating the client, and that code will magically appear in the client executable?

    Obviously that can't work without patching the client - which is often not something we can do, or rely on happening when we'd like it to. Whatever solution you end up with should either a) make it very clear that new code is being required when you build new bundle data so that you know you cannot ship them without a client update or b) preferably allow us to mark which subsystems we want to include/strip manually, so we can include them before assets which use them are made.
     
    AcidArrow likes this.
  13. superpig

    superpig

    Quis aedificabit ipsos aedificatores? Unity Technologies

    Joined:
    Jan 16, 2011
    Posts:
    4,153
    No. If you didn't have any particle systems in your game, and then you ship an asset bundle which adds a new particle system, then that is not "new content - new data for systems that are already built into the game."

    Sure.