- Home /
Compilation order, scripts in "Plugins" can't access full .Net
As simple as possible: In one script, i use System.IO.DirectoryInfo.GetFiles (string pattern). This works great, however if I place the script inside the Plugins folder (or actually Plugins/Editor instead of just Editor). I get a compiler error saying that DirectoryInfo doesn't have the function GetFiles. Really odd since the System.x classes shouldn't have to be compiled differently depending on where in the compilation order a script in Unity is, they should always be compiled first, shouldn't they?
Thanks
Not sure that the System.IO stuff is compiled at all - will be byte code in those things.
The point is that it works when placed outside the Plugins folder. (in Editor/myscript ins$$anonymous$$d of Plugins/Editor/myscript). I'm not building anything, it's from the compilation for the editor I get the error. System.IO.File.ReadAllText doesn't seem to work either.
Answer by Aubrey-Falconer · Dec 22, 2011 at 06:53 PM
Sorry to answer such an old post - but Unity searches anywhere, any numbers of levels deep for editor folders - except in /Plugins or /Standard assets.
If you want to include editor scripts in Unity's first compilation pass, they must be placed inside /Assets/Plugins/Editor/.
Answer by Waz · Jun 28, 2011 at 01:18 PM
Are you building for WebPlayer? File access is not permitted there. It's a sandbox.
Not building for anything, just inside the editor (see comment on my question).
Doesn't matter. If your build setting target is web player then chunks of API are not available, except to Editor/ files.
Ok, what seems to be the problem is that my folder structure looks like Plugins/somefolder/Editor/myscript. And Unity doesn't seem to recognize the Editor folder scripts as Editor scripts. It works when the folder structure is Somefolder/Editor/myscript though, but perhaps Unity only searches two levels deep for editor folders. And I need to place the Somefolder folder there because I'm going to release this on the Asset Store, and they require that structure. The reason I need it in the Plugins folder in the first place is because the scripts need to able to be reached from Js.
And you are correct, since my scripts weren't recognized as Editor scripts, they didn't have access to that API any more.
Answer by demize2010 · Jun 28, 2011 at 01:40 PM
Seems like a weird error, could be to do with the compile order?
http://unity3d.com/support/documentation/ScriptReference/index.Script_compilation_28Advanced29.html
What happens if you put that function outside of Editor et al and call it with a SendMessage?
Yes it has to do with compile order (look at the question name). And you cannot call that function with Send$$anonymous$$essage since it is not in another script, it is in a .Net class.
Your answer
Follow this Question
Related Questions
Recompiled plugins not refreshing in Unity 1 Answer
Speaker/earphone audio output toggle from unity c# script using "Lesser AudioSwitch" app 0 Answers
Google Admob error, Unable to resolve reference 'UnityEditor.iOS.Extensions.Xcode' 0 Answers
What is the general use of Awake(), Start(), Update(), FixedUpdate(), LateUpdate()? 7 Answers