2

In a Unity 4.1 project, I would like to have all my C# scripts in DLLs. Unity creates a Visual Studio project and I'm able to compile the code correctly. The compilation produces the DLL but Unity does not recognize all classes, just those that inherit MonoBehaviour. All classes are public and Unity is Pro. How can I make Unity 'see' all classes?

I tried compiling with Mono 2.8, it built the DLL. All the classes seem to be there, but nothing works and I get these errors:

    ApplicationException: Unable to find a suitable compiler
    UnityEditor.Scripting.ScriptCompilers.CreateCompilerInstance (MonoIsland island, Boolean buildingForEditor, BuildTarget targetPlatform) (at                                                         
    C:/BuildAgent/work/7535de4ca26c26ac/Editor/Mono/Scripting/ScriptCompilers.cs:99)

and

    Failed to create compiler instance

2 Answers 2

3

Ensure you are compiling the DLL against .NET framework 3.5 or lower.

To change the targeted .NET Framework version in an existing project:

  1. Open the project you want to change.
  2. In the Solution Explorer toolbar, choose the Properties button.
  3. You can also select the project node in Solution Explorer, open the context menu (by right-clicking the node), and select Properties.
  4. You should see the settings on the Application tab. If you do not, select it.
  5. In the Target Framework dropdown list, choose the .NET Framework version that you want. Then click the OK button.
Sign up to request clarification or add additional context in comments.

3 Comments

Targeting this version makes a lot of correct code to not compile. Like default parameters and default get/set property accessors.
Unity is only binary compatible with .NET 2.0 DLL. So you have only 2 way to go: 1. compile it in Unity. 2. compile it in .NET 2.0
Note - I believe Unity3D v4 can actually utilize .NET 3.5 and lower DLLs. I have updated my post to suit. Most confuse this with Unity's own internal Mono version of .NET, which is closer to v2.0.
0

SOLVED

I'm using Visual Studio 2012 for compiling the DLL's, both runtime and editor. Targeting .NET 3.5. This post helped me a lot: http://forum.unity3d.com/threads/148078-Reducing-script-compile-time-or-a-better-workflow-to-reduce-excessive-recompiling?p=1026639&viewfull=1#post1026639

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.