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 eliminiate 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.

Tweaking export type

In many instances developers have required assets referenced via direct or indirect links from scene objects. Consider the following example:

optimising-your-builds-overview-download

Having this scene set up for export will make Luna automatically discover it needs to include Cube mesh as well as Default-Material material; the material will then reference some built-in textures like UnityWhite as well as Standard shader and those will also make it into the build.

If the developer is sure the code doesn't use any implicit references, it would make sense to swicth the export type. This can be done by navigating to "Basic Settings" section of Luna UI and switching the export type to "Selected Items" leaving only "Scenes" checked:

optimising-your-builds-excluding-export-type

Options for "Prefabs" and "Scriptable Objects" exist for situations where you want to include prefabs or scriptable objects respectively and ignore other bits like textures.

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 speific ones.

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

optimising-your-builds-excluding-force-include-exclude
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 depdendencies 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 accidentially 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 irrevertable, 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 accidentially 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.