- Home /
Script Compilation Order not working
Edit 2 : This question has been answered, but if I could draw your attention to the comments under the answer. I have multiple different classes using Path, yet have only imported the namespace on one script, and the project works. This is contradictory to the comments. While I don't doubt any of the information provided to me (and I really appreciate all the information), this raises a curious question. Why does it work when import Pathfinding; is only declared on one script?
Edit : After help from Bunny, I realize now that Script Execution Order was never going to fix my problem. This was a last attempt to get my scripts to compile in the correct order, after putting everything C# into the Plugins folder failed. Have updated the title (originally Script Execution Order Settings not working).
To summarize : all C# scripts are in the Plugins folder (or subfolder therein), except for the Editor scripts which are in the Editor folder (or subfolder therein). All uJS scripts are in my _Scripts folder.
Original Question :
I'm trying to use Aron Granbergs Pathfinding. For some strange reason I cannot get the Path script to compile before any of my uJS scripts. This is the second project I have used this, and the first time I had this problem. I tried making a new project, and imported the Pathfinding Project first before a backup package of my project, still not working.
I have changed my folder setup for uJS : http://arongranberg.com/astar/docs_dev/javscript.php
I have also tried to use the Script Execution Order Settings : http://docs.unity3d.com/Documentation/Components/class-ScriptExecution.html
This is doing my head in. What am I doing wrong? Seeker is recognized, but Path is not.
private var seeker : Seeker;
private var path : Path; // line 42
function OnPathComplete( p : Path ) // line 111
{
if ( !p.error )
{
path = p;
currentWaypoint = 0;
}
else
{
Debug.LogError( p.error );
}
isCalculatingPath = false;
}
Answer by Bunny83 · Jul 23, 2013 at 11:30 PM
Script Execution Order is only to control the order in which Update / Awake / Start /... are called. It has no meaning to the compiler. The compiler only creates 9 .NET / Mono assemblies, 3 for each language. Of course if you don't have a script in one of the languages it won't create that assembly ^^
For each language Unity might create those 3 assemblies:
Language first pass
Language (main)
Language Editor
Everything in the plugins or Standard Assets folder will go into the first-pass assembly. All scripts outside of the special folders will belong to the usual (main) assembly. Everything in an editor folder will be compiled into another seperate assembly. Only the first two are actually included in your game. The editor assembly exists only inside the editor.
In general: In any first pass assembly you can only use stuff from one language and only the scripts that belongs to the first-pass group. The normal (main) assembly can use all first pass assemblies no matter of what language. However the normal group can't access any stuff of other normal group scripts that are written in a different language.
It works like this:
In order to use stuff from another language it has to be already compiled in an assembly. Unity has two compilation steps: first pass and main pass. When compiling the main pass Unity can link all the first pass libraries and use what's in there.
Since your PlayerBuilder script is in the normal (main) group all your C# stuff has to be in the first pass group, so make sure all classes that belong to the Pathfinding library are either inside the plugins or Standard Assets folder.
edit
I just spotted your mistake ;)
Aron just keeps his code clean (as it should be). All his stuff is in a seperate namespace called Pathfinding. Unity even suggests this in the error ^^
So in your JS script either use:
private var path : Pathfinding.Path;
or add an import statement at the top:
import Pathfinding;
and it should work ;)
btw Mono usually can do this for you when you right-click on the Path type in your script and select "Resolve".
Thanks again for the reply.
That is the problem, everything is in the Plugins folder. Even when I drag Path out of the subfolder directly into the Plugins folder, the error persists. What is more perplexing is I did exactly the same approach as the first project I used it. Import A*, rearrange folders for use with uJS (everything in Plugins or Editor folder as applicable), and the code in the uJS script is exactly the same as what I've used previously.
Script Execution Order was a last failed attempt to fix the problem. I had my suspicions about it not being applicable to this when I realized I was putting in time values. Thank you for the explanation.
So why is Unity not including Path in the first pass? I am at a total loss (this is for my $$anonymous$$iniLD44 entry too).
As in the image in the question, you can see where the files and folders are.
I am so sorry for wasting your time. Checking my first project, I did use import namespace. Thank you for your help, sorry that it was silly mistake.
Hi again, one more hopefully not-so-silly follow-up question.
When I looked back at the first project after your answer, I opened a NPC script and found I had declared import Pathfinding;
Today I went back to another NPC script I was initially using for reference yesterday, and found I had not declared import. This is where my problem in the question started.
So when I declare import in one $$anonymous$$onoBehaviour in my scene/project, does it imply this for all $$anonymous$$onoBehaviours?
I know this question is revealing my lack of understanding, I have only seen import mentioned in the array documentation (http://wiki.unity3d.com/index.php?title=Which_$$anonymous$$ind_Of_Array_Or_Collection_Should_I_Use?). Also on relection, I have a project that takes a long time to initialize where I have used import System, System.Collections, and System.Collections.Generic in multiple scripts.
Should I just make one helper class for my projects with import namespace; ?
No, each script needs it's own "import" statements. $$anonymous$$eep in $$anonymous$$d it's just a shortcut for the compiler, so you don't have to write the whole namespace all the time you use a type / class from a certain namespace.
Personally i never import the System namespace in Unity scripts since it just causes too many problems with collisions with the UnityEngine namespace. If i need something from the System namespace i use the whole name ins$$anonymous$$d.
Ok, well I am now very confused. Here are some screenshots to show I'm not completely full of stuff and nonsense.
Here is the project running, with the first NPC I made to test and learn the Pathfinding Project : https://www.dropbox.com/s/202uxkvzb74lzbr/enemy_1.jpg
This is the active object linking to the script : https://www.dropbox.com/s/fj94og99e66n962/enemy_2.jpg
And here is the preview of the script : https://www.dropbox.com/s/rw2lsap5uszcoog/enemy_3.jpg
So that was the first NPC with the import declared. Now here's the second NPC, a modified spider from AngryBots :
spider selected : https://www.dropbox.com/s/4usdjryq6nislpm/spider_1.jpg
showing the script component : https://www.dropbox.com/s/3qhq7ev4mwu614w/spider_2.jpg
script preview : https://www.dropbox.com/s/g9u2vagaf9bssk3/spider_3.jpg
With no import. I made sure to check all the attached scripts didn't have import before posting this. And the other NPC scripts :
I am more than happy to upload the project for you to check (if you would like to).
There is no problem, you have answered my question and I now understand where I went wrong in my new project. This is turning into a 'how to use namespace' question, but I am curious why this is working under the current setup, as it seems to contradict the last few comments. Thank you for your time.
Your answer
Follow this Question
Related Questions
Script Execution Order removes scripts on apply 1 Answer
Ask for Script Compilation from EditorWindow Button 1 Answer
Editor Scripts in Dll 1 Answer
Prevent a script from compiling ? 2 Answers
How to get faster script compilation? 6 Answers