At some points I need to set a script aside and not include it in the compile, as it contains too many compile errors and I know I will come back to it, but in the meantime I’ll work on others. Regardless of whether or not that in itself is a good idea, is there a place inside ‘Assets’ I can move the script to, where it will not compile? Or a folder I can stipulate as ‘do not compile’? At the moment I’m commenting out the entire script so I can compile without it, or I suppose I could move it in the Finder, but I’d rather move it within the Unity IDE…
I’ve just ran into a situation where I needed that, and while dragging files out of the Assets folder certainly is an option if you’re not using version control (Asset Server, Subversion or anything like that), when you do use version control, that’s not an option.
The reason I needed this was for keeping HTML-JavaScript files in the project, and there’s a really good solution that you also find in the documentation:
Overview: Script compilation (Advanced)
So here’s the trick (it’s a bit down the page):
Additionally, any scripts in a folder called WebPlayerTemplates will not be compiled at all.
So, simply create a folder WebPlayerTemplates (below your Assets folder), and you have an area which still is under version control but is not touched by the compiler. Awesome
Personally, I just use a conditional directive…
#if false
class foo : MonoBehaviour
{
// rest of your code.
}
#endif
I’ve always just dragged them out of the Assets folder. What’s wrong with that?
Some good answers here already, here is another option to consider.
For my projects I use external version control, not Unity’s built-in version control. I always set up my project structure so that the unity folder is a nested folder, not the top-level folder. This lets me have other folders in the project that are not visible to Unity. This layout would let you move non-compiled source files out of the Unity Assets folder without moving them out of your project.
Note that if your code is compiled in Visual Studio into a DLL then the source code itself is not under the Assets folder. In your Visual Studio solution you can either remove a source file from the project (but not delete it from the hard drive) or right-click on the file, view properties, and change the build action from Compile to Content – this keeps it in the project but does not compile it.
Here’s my typical top-level structure:
/MyProject
/unity
/Assets
/Library (excluded from version control)
/ProjectSettings
/source (source code gets compiled into DLL's)
/<more> (whatever other folders you want)
You can just put your sources in a hidden assets folder (Unity - Manual: Special folder names).
Any folder starting with “.” or “~” is hidden in the editor and the content is not compiled nor imported.
For me better solution was to add a “~” to the end of the folder name like on the docs:
So it’ll:
- not compiling on Editor
- not included on Builds
- not be visible inside Unity Editor project tab
- not be hidden on Windows or Linux
- have as many folders as you want, starting with the alphabetical order you want
But if I need that folder to be under Unity’s built-in version control, I need to put inside:
WebPlayerTemplates
It’ll continue to work with the 5 points mentioned before, except that will be visible on editor project tab, at least on Unity 2019.3.x
There is now an editor extension for this, available here.