- Home /
Why are only certain .NET libraries available in Unity?
When I try to use System.Drawing
I get this error:
Assets/Scripts/TileCanvas.cs(3,14): error CS0234: The type or namespace name `Drawing' does not exist in the namespace `System'. Are you missing `System.Drawing' assembly reference?
I am most certainly not missing the System.Drawing
assembly reference. Moreover, when I look at the list of all references there's nothing to distinguish System.Drawing
from any of the namespaces that work just fine. So how am I supposed to tell the difference between references that work and references that don't before I see the error message?
I don't actually need help getting rid of the error message because I found that answer here: http://answers.unity3d.com/questions/53170/using-drawing-package-like-systemdrawing.html . But my question still stands about why Unity works this way.
Also, System.Drawing.Size
has a SerializableAttribute
. So why can't I set its properties in the inspector?
Answer by Bunny83 · Oct 03, 2017 at 02:24 AM
Unity doesn't use the .NET framework but an old version of Mono. The only exception is the WindowPhone build target which actually uses .NET. Of course Unity does not include all the standard libraries since they all would need to be shipped with your game.
Unity is not a .NET or Mono application. Unity is written in C++. It just uses Mono / .NET as scripting environment.
Manually adding references to assemblies in MonoDevelop or VisualStudio is pointless. Unity doesn't use the ".csproj" file at all. It only creates this file so the code editors get all the information they need. Unity compiles the actual assemblies directly with the shipped Mono compiler.
If you actually need an assembly which is not part of the core, you have to copy it into your assets folder of your project. Keep in mind that you may need to copy also other assemblies where the imported assembly depends on. Also note that some assemblies of the .NET framework can't be included into Unity as they may depend on OS specific implementations (like Windows Forms).
ps: If you had searched first you should have found tons of similar questions like this, or this, or this
ps: It's true that the Size struct inside the System.Drawing namespace is marked as Serializable, however it doesn't have any fields that can be serialized. The struct has only private fields which aren't serialized by Unity. Properties are never serialized by Unity's serializer.
Thank you, that's very informative. And yes, I did find those similar questions. There's just one more thing I'm trying to get answered. If Unity doesn't use .NET then why are some namespaces available like System.Collections
? And as I was asking before, is there any way to tell the difference between the namespaces that are available and the namespaces that aren't?
Because $$anonymous$$ono is an open-source implementation of the .Net framework, so you will be able to use namespaces such as System.Collections
. I don't know where to find the "available" namespaces though.
Your answer
Follow this Question
Related Questions
How do you organize your own "framework" code? 1 Answer
Using a .embeddedframework (ios) in Unity - EntryPointNotFoundException 0 Answers
Create a framework bundle for Standalone build 0 Answers
objective-c method call from unity 1 Answer
Getting a Build error for Windows Phone 8 Platform, It's working fine in PC 0 Answers