- Home /
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?
@$$anonymous$$ 4 Bunny83's answer is the best and only correct one, if it's not too much trouble, please switch the "Best Answer" flag over to his answer.
Answer by qJake · Jul 30, 2010 at 06:00 PM
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:
if(Application.isEditor)
Just use that condition everywhere in your class to stop it from running outside of the editor, on client machines.
I appreciate the info on excluding code from running outside the editor, but in this case, I want to exclude specific art assets from the build.
$$anonymous$$aybe if you placed it in Assets/Editor it would not get put in a build?
Answer by titin_lc · Apr 25, 2013 at 02:43 PM
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
BuildPipeline.BuildPlayer(...);
// Restore assets to Resources
UnityEngine.Debug.Log(AssetDatabase.MoveAsset("Assets/blablabla", "Assets/Resources/blablabla"));
// I don't know if this is necessary
AssetDatabase.DeleteAsset("Assets/blablabla");
// Refresh database
AssetDatabase.Refresh();
That's a bit of an overkill but of course works
if you have Unity pro
;)
I've posted an answer which makes your life a bit easier ;)
looking for this to exclude asset bundles in resources folder, thanks heaps...
This is obsolete since Unity 5.x where they basically removed almost all differences between the personal and plus / pro versions. Now Unity has exact the same features regardless of the license. The only things that remain pro / plus only are:
The dark pro editor skin
Splash Screen removal
For anyone reading this in the future, keep in $$anonymous$$d that things can change over time.
Answer by Waz · Feb 10, 2011 at 01:05 AM
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.
Answer by rodger_hu · Jan 23, 2014 at 03:50 AM
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 :)