Excluding Assets From Build

Similarly to a widespread proverb "the fastest code is the code which does not run", the easiest way to reduce build size is to remove some assets completely. As outlined briefly in the previous section, it is sometimes useful to completely eliminate certain things, especially the ones residing in Resources folder so that they don't take space in the build. Luna (and Unity) is unable to do that automatically as user code can always request loading of an asset with Resources.Load API with the name constructed dynamically, thus Luna has to keep everything in resources folder. There are a few options available to aid the situation.

How Luna exports using your game scene

By default Luna detects all assets in use by the scenes you have selected in the plugin window, this includes: all prefabs, textures, animations and other resources found in the project.
Whilst this strategy often produces undesirably big builds, especially with games which have a lot of assets, it is a preferable starting point because it helps avoid issues caused by misconfiguration and eases debugging of first exports.

If you wish to include additional resources you can:

  • Select "Resources" to include the Resources folder
  • Select "Streaming Assets" to include the Streaming Assets folder
  • Manually include specific assets as documented here
images-medium


If you want to start thinning down your build a good place to start is with excluding assets, which is explained below.

Excluding or including individual assets

There are instances when more fine control is needed: for instance, you might have 20 prefabs for different levels, but you know your playable ad will only load the first 3. Instead of reorganizing your project structure, you can force Luna to include specific assets or, otherwise, force to exclude specific ones.

This can be done simply by navigating to the Assets section and the Assets tab, and marking an asset or even a whole folder in corresponding parts of the screen:

images-medium
Force-include always wins
Please note that "Force Include" section has the highest priority: assets selected there will get into the build along with their dependencies even if they are excluded by all other means.

Next steps

The above controls should be sufficient to configure any sort of membership of assets within a given project. Please note that Luna export will do its best to avoid broken references and otherwise invalid state: it will propagate inclusion status to any dependencies, i.e. include textures referenced by a material if the material gets it into the build.

It is possible, however, to break that. For instance, one can accidentally force-exclude a texture used by a material on the scene that is not a member of "Force Include" section, so excluding the assets must be done with care. Nothing is irreversible, though: Luna will never delete anything from a Unity project and restoring any previous settings is as easy as checking out a previous version of luna.json file shall a developer accidentally break a Luna build by excluding too many assets.

If all assets are excluded, but the build size is still undesirably big, it is a good time to try applying specific compression settings to individual items as described in Optimising Assets section.