► Exclude from build: files, objects, components ◄

Hi all,
I have made an asset which allows you to exclude anything from your build (file, folder, script, GameObject, Component). It's super easy (just right-click and hit "exclude from build").


> Asset Store Page <
Full Source Code included.

Here is the thread which triggered me to grow my home made tool into a full featured asset:
https://discussions.unity.com/t/629256 page-2


Can exclude any file (yes scripts files too), GameObjects or Components
Test Mode (allows you to see your changes withou having to start a build)
Allows you to make multiple configurations per platform (called "groups")
FullSource code included
Overview window with handy shortcuts (so you always know which things are excluded and where to find them). You can also scan scenes for excluded objects or components.

If you want to know more then here is the manual (pdf):

Hope you'll find it useful :)


Hey, can you use this on folders in packages too?
Currently having a major issue with a project, that includes multiple build types on the android platform. One library from a package seems to get included and mess with the rendering pipeline, so one build type does not work anymore. Its a .o library inside a package, that is included via package manager. Would this tool be able to exclude the file from build?

Hi, good question.

Sadly no. The tool only works on things WITHIN the Assets/ folder. Though package support seems to be an often requested feature. I have it on my todo list to look into it (no promises though).

One way to solve this manually could be to turn the package into and embedded package and then use #ifdefs to comment out the problematic code segments. Caveat: this does require you to redo the changes for every package update. It's not very maintenance friendly.

Another solution would be to use a different package manager manifest file for each platform (just an idea, I have not yet tried this myself).

Sorry I don't have better news for you. I hope this answers your question.

Very interesting asset!

I often make a build in a project with a lot of textures that are not needed/used in the build, but they are in the project as part of an asset that I got from the store, now the thing that unity does is the following, it compresses each and every texture in the project when making a build, taking a long time and if those textures are not even part of the build thats a wast of time and disk space. Do you think that with this asset will allow the compressing of those not part of the build textures will be skipped so I can have faster builds? Thanks

thank you.

They way it works is that if you start a build the tool will hide all folders and files which are marked as excluded BEFORE the build starts. The files are then no longer in the AssetDatabase. Then Unity builds. Afterwards the files are made visible again.

People reported significant build size reductions due to excluded textures. So I think, yes, it should do what you want. Caveat: I have not yet tested this exact (texture compression) use case.

I am curious: I usually only see long lasting texture tasks after a platform switch, reimport or very first build. I guess you are already using the cache server?

1 Like

I don’t use the cache server, and yes I do platform switch a lot, I also want to save on disk space by not compressing whats not needed in the build. I will buy the tool as it seems perfect for it.

In thing that would make it even better if it could detect scene dependencies of textures, but I understand that may be out of scope for this asset.

[quote=“Lars-Steenhoff”, post:6, topic: 883007]
if it could detect scene dependencies of textures
I fear I don’t quite understand what you want the tool to do here. There are some really good “reference finder” Assets out there which help visualizing what is referencing what. Not sure if that is what you want though.

[quote=“Lars-Steenhoff”, post:6, topic: 883007]
I don’t use the cache server, and yes I do platform switch a lot
I don’t mean to push it onto you but I really recommend using it. It makes a big difference. It’s one of the first things I enable for any project. Otherwise platform switching is just such a pain.

One thing that will be nice to have is a hiding set, that I can enable / disable

Yea I was thinking about a reference finder that automaticity set the excude tag to a folder if not referenced by the scenes in the build

I see there is now https://docs.unity3d.com/Manual/UnityAccelerator.html accelerator as cache server only works on older unity versions. I will have a look again there. bit its still wasting a lot of disk space that I rather keep on my system SSD. thanks for the tips.

[quote=“Lars-Steenhoff”, post:8, topic: 883007]
Yea I was thinking about a reference finder that automaticity set the excude tag to a folder if not referenced by the scenes in the build
Ah okay, now I think I understand. Though in builds these unreferenced things should not be included (or processed) anyways (unless they are in a special folder like Resources, StreamingAssets).

It might be a handy feature to “hide” things in the Editor to keep the project clean after importing 3rd party assets. I’ll think about it. But I guess this would become a new asset since it’s not really in the scope of “exclude from build”.

Thanks for the feedback :slight_smile:

1 Like

Or textures, they are always compressed no matter if they are in the build or not.

I think unity has some plans to change this later. but seems to take forever to get released.
First Link here #8

Second one #6

1 Like

I understand your problem and I agree that asset importing is a bit of a pain.

I think the key part is "The compressed result is still an import artifact and it is cached in the asset database ..". Usually once you have the cache server (accelerator) enabled and you have built at least once for every target then you should have cache hits for about 99% of all textures and import times won't play a big role anymore (for building or platform switchting). But I am not entirly sure how the "uncompressed texture" workflow works (I rarely use uncompressed textures).

I assume every time you do a platform switch the import artefacts are thrown away unless you have a cache server where they are stored. My understanding of the cache server is that it exists to retain the imported results and share them among coworkers. In your case (no cache server) all those textures have to be reimported at build time. I think you will have massive gains in build times once you switched to the cache server / accelator workflow.

I think the topic may be a little out of scope for this thread though.
Maybe continue in the original thread you linked?

1 Like

Answer to a question raised in another thread:

At the moment these are not configurable. I’ll add a “can be moved to other location” feature to my list of things to investigate.

However, if you want them to be located somewhere else you can look into to source files (ExcludeFromBuildData.cs and ExcludeFromBuildSettings.cs). Right at the start you will find the locations:



Hope this helps anyone who wants to change the default location of the config files.

1 Like

Many thanks for the clarification.

Three more things.

  1. The red thingy that's displayed on an excluded folder is a bit small. Could there be an option to switch it for a bigger sprite, especially for users who rely on small one-column displays in the Project tab?

  2. Also, the red sprite is displayed or not depending on the excluding group that is currently selected. Which means that unless we select the right group (the active one), it's totally possible to miss the fact that a folder is excluded by looking at the project tab directly. I think it would be great that another sprite reflects that status, but that comes in another color, like that of an inactive state, if the corresponding group is not selected.

  3. With this in mind, the right-click button may open a menu that displays the first function, exclude from build, and then underneath it, a list of all saved groups in which this folder will be excluded during the building, just to go faster and avoid having to look into all the groups manually in the EFB window.

1 Like

Hi, thanks for the feedback. I have written down your suggestions on my list of things to investigate (no promises though). The part about non-active groups not being shown is a good point.

The icons themselves are based on internal Unity icons so I don't (yet) know if there are some variations with different colors. I'll have to check.

They are drawn in the ProjectWindowDecorations.cs file.
As a quick fix you could change the sizes like this:


To show the icon for all groups you could add a new method to the ExcludedFromBuildData, like this:

public bool IsExcludedInAnyGroup(string guid)
   if (Groups == null || Groups.Count == 0)
       return false;

   foreach (var group in Groups)
       if (group.ExcludedObjects == null || group.ExcludedObjects.Count == 0)

       foreach (var obj in group.ExcludedObjects)
           if (obj.AssetGUID == guid)
               return true;

   return false;

And then again in the ProjectWindowDecorations.cs replace the IsExcluded with IsExcludedInAnyGroup.

That would show it for all groups and would not differentiate between the current or the other groups but it's a start.

I hope this helps you out for now.

Right, thanks.

I always get this error when I create builds:

ExcludeFromBuild: An error occurred while renaming files or folders: Access to the path '<path>' is denied. Path: '<path>'

ExcludeFromBuild: Maybe your IDE is locking some files. Please try to close it or make it unlock the files you are excluding.

ExcludeFromBuild: Renaming files or folders FAILED. Aborting and reverting. NOTICE: no files or folders will be excluded in this build!

Is there any way for this asset to work while Visual Studio is opened? Maybe there's a way to tell VS to ignore certain files? This would be a huge limitation otherwise, because you normally wouldn't close VS every time you create a build (in fact, I usually forget about this until I see the error).

Hi, sometimes it is the windows defender that locks the files not VS. Could you please try adding your Unity project to the exclusions list.

Usually having VS open is fine. I have just done a little test build with VS 2022 and it worked. Sadly this issue comes and goes. I do not really know when/why VS sometimes keeps locking some files so I am not sure how to resolve this in a better way (sorry).

All right, thanks for your reply.

It looks like my project folder was already excluded in Windows Defender. I know what you mean, though — file locking seems kind of random and hard to debug. I'll see if the problem is consistent or not.

1 Like

Great asset, thanks for making it!

Hoping you can answer a question before I go digging in source to figure it out... is there a way to easily query the Active Group selection from code to do some other branching in post-process build scripts? It would be great to be able to use this as a singular control variable for both OS and distribution platform logic in my build scripts (instead of the usual messy #defines approach).

e.g. psuedo code

if (ExcludeFromBuild.ActiveGroup = "SteamWin64")
    // Don't run this post process build script

if (ExcludeFromBuild.ActiveGroup = "AndroidAmazon")
   // Do something specific for this build config

yes, you are actually close with your code.

It's all stored in the ExcludeFromBuildData object which you can access via the static method ExcludeFromBuildData.GetOrCreateData().

if (ExcludeFromBuildData.GetOrCreateData().CurrentGroup.Name == "Whatever")
    // Don't run this post process build script

The current group is an object with some properties. I think what you would want is the "Name" or maybe the "BuildTargets" to make it independent of the name.


Hope that helps. Feel free to ask again if you need anything :)

1 Like