Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unity3d reference issue with C# projects

Tags:

unity3d

In my Unity project I have 3 visual studio projects: Assembly-CSharp-vs Assembly-CSharp-firstpass-vs Assembly-CSharp-Editor-vs

All my scripts seems to end up in Assembly-CSharp-firstpass-vs, but an imported asset I'm using (2dtoolkit) has the code in Assembly-CSharp-vs ... Which means that I can't access this code from Assembly-CSharp-firstpass-vs, because there is no reference to Assembly-CSharp-vs (there's not supposed to be a reference that way).

So, what is the "correct" way to handle this? I imagine that either I must move my script files to Assembly-CSharp-vs, or I must move my asset sources to Assembly-CSharp-firstpass-vs..

like image 947
bendahmon Avatar asked Jul 03 '12 08:07

bendahmon


People also ask

Can you use C in Unity?

Unity supports the C# programming language natively. C# (pronounced C-sharp) is an industry-standard language similar to Java or C++.

Is C sharp for Unity?

The language that's used in Unity is called C# (pronounced C-sharp). All the languages that Unity operates with are object-oriented scripting languages.

How do I fix NullReferenceException object reference not set to an instance of an object?

The best way to avoid the "NullReferenceException: Object reference not set to an instance of an object” error is to check the values of all variables while coding. You can also use a simple if-else statement to check for null values, such as if (numbers!= null) to avoid this exception.

How do I fix NullReferenceException in Unity?

This error is caused when an object is trying to be used by a script but does not refer to an instance of an object. To fix this example we can acquire a reference to an instance of the script using GameObject. Find to find the object it is attached to.


1 Answers

If your scripts end up in the Assembly-CSharp-firstpass-vs project, it means that somewhere upwards in their folder hierarchy you have a folder named "Plugins", "Standard Assets" or "Pro Standard Assets". This causes you scripts to be compiled in the first of 4 possible compilation steps. So Unity will therefore place your code files in the Assembly-CSharp-firstpass-vs project.

To make it possible to access 2DToolkit from your code I would recommend that you move all of your script files so they are not placed under any of these folders. This will cause them to be placed in the Assembly-CSharp-vs project.

If you are using C# it should work now. But if you have written your own code in UnityScript(JavaScript) or Boo, you will have to place 2DToolkit in a folder named Plugins (or "Standard Assets" or "Pro Standard Assets" if you prefer that) so it compiles before your code.

Take a look at the Script compilation page in the Unity manual for more in-depth information of how you can control the script compilation order.

like image 50
TrolleFar Avatar answered Oct 20 '22 04:10

TrolleFar