- Home /
Can I put scripts somewhere so they don't compile?
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...
Answer by jashan · Dec 14, 2012 at 08:33 PM
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 :-)
You're very welcome! And thank you for accepting this as answer, Robin!!!
I remember we had that question already several times. Too bad we can't group similar questions...
Just a note for anyone having trouble using the WebPlayerTemplates folder for this: It apparently has to be in the root of your Assets folder. It can't be in any sub folders, or else the scripts inside still get compiled. At least that's what was happening for me. (Unity 3.5).
Answer by testure · Jul 01, 2011 at 03:15 PM
Personally, I just use a conditional directive..
#if false
class foo : MonoBehaviour
{
// rest of your code.
}
#endif
Answer by flaviusxvii · Jul 01, 2011 at 03:05 PM
I've always just dragged them out of the Assets folder. What's wrong with that?
Fair enough! Sounds easy, I was just being too lazy to switch to the Finder :)
although, once you drag it out of your assets folder you're not able to access it from within Unity. If you wrap a conditional directive around your code, it will stay in the assets folder so you can access it from within Unity, but it still won't compile.
I guess it all depends on what you need to do
Just shove it out of the way while I work on something else... So I just drag it back in when I want to come back to it. So your way is probably the simpler way for me for now.
There's two problems with this approach:
a) you can't do it within Unity b) if you're using version control, you lose the history
See new answer (below) for a better approach: There actually is such a folder, and it's called WebPlayerTemplates
Answer by yoyo · Jul 29, 2014 at 05:29 PM
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)
Your answer
Follow this Question
Related Questions
How can I tell what's happening during Compile? It's taking way too long, and doing too many things. 0 Answers
Wait until scripts compile 1 Answer
Does "Pixels to Units" on importing assets affect performance? 0 Answers
How can I allow the device Camera to insert face on actor? 0 Answers
How do I not use a script? 2 Answers