Can I exclude specific assets in Assets/Resources from the build?

I have some files in the Assets/Resources directory that are needed in the editor for debugging, but I would like to exlude at build time. Is there a way I can script the build process to exclude specific assets?

Yes, you can. You need to build by script, but first move out the resources you want from the “Resources” folder. And after building, restore those files. Try the following:

// Move assets from Resources
UnityEngine.Debug.Log(AssetDatabase.MoveAsset("Assets/Resources/blablabla", "Assets/blablabla"));
// Compile on work folder

// Restore assets to Resources
UnityEngine.Debug.Log(AssetDatabase.MoveAsset("Assets/blablabla", "Assets/Resources/blablabla"));

// I don't know if this is necessary

// Refresh database

Resources are always included, so if you're trying to save space in output, you will HAVE to move them out of a Resources directory.

However, any GameObject in the hierarchy that is tagged with "EditorOnly" will not be included (nor will its non-Resource dependencies), and you never NEED to use Resources (you can always just reference the asset as a parameter to the GameObject).

So, for example, have a "DebugConsole" object in your scene, tag it with EditorOnly, and have its assets as variables that you configure. Obviously if this GameObject is needed in every scene, you'll want to make it a Prefab and copy it to every one.

Just in case you didn’t know this one:


Unity3d document say: Additionally, any scripts in a folder called WebPlayerTemplates will not be compiled at all.

So, Move all you don’t want compiled resource to WebPlayerTemplates folder. may be you need create WebPlayerTemplates folder first.
sorry by my bade english :slight_smile:

Since 5.3.2 you can exclude files and folders from build with “~” suffix.
See 5.3.2 Release Notes (687655), and the updated Unity - Manual: Special folder names.

You may or may not be able to exclude files (I don't think you can), but if you've written your own Debug class, you can stop it from working outside Unity by using a check:


Just use that condition everywhere in your class to stop it from running outside of the editor, on client machines.