- Home /
Properly using a Managed C# .Net DLL
I am trying to use a Managed C# .Net DLL for parts of my code that I wish to keep secret(by later obfuscating the DLL); Well, it turns out that I cannot use MonoBehaviour inherited classes from within my DLL inside of the Unity3d Editor. Initially I got the error, that my class couldn't be found(which is located in my DLL). Finally I got past that, by making a C# file in my project that inherited from my class in the DLL, but I quickly got another error that wouldn't let me access variables from my inherited class(which is inside the DLL);
This is becoming very annoying, and I hope someone knows a way around these issues. Thank you.
Answer by Lucas Meijer 1 · May 14, 2010 at 09:19 PM
Classes in your dll are just like any other classes, except that we don't support you assigning monobehaviours from your dll to a gameobject. It's fine to have a small script outside of your dll that does enherit from a class in your dll that has "the meat". If you cannot access members of that class, that sounds like an issue with the accesibility of those members. You might have them set to private, or internal. Make sure the type itself and the method/field in question are both public.
Answer by N1nja · May 14, 2010 at 09:38 PM
In my Managed C# DLL:
using UnityEngine;
namespace My.Namespace
{
public class MyCustomBehaviour : MonoBehaviour
{
public int myVariable = 0;
}
}
Inside Unity Project:
using UnityEngine; using My.Namespace;
public class CustomBehaviour : MyCustomBehaviour
{
public int Variable {
get { return base.myVariable; }
set { base.myVariable = value; }
}
}
The above does not work. Any ideas?
That code looks perfect. Can you put the .dll online somewhere? Which version of Unity are you using? What is the exact error that you get?
Answer by Phenotype · Nov 13, 2010 at 06:30 PM
I have the same issue. Unity requires your custom behaviour to derive directly from MonoBehaviour. The work around is to use your custom behaviour class as an adaptor. You then put your application logic in other classes that are referenced by your behaviour class.
Answer by boymeetsrobot · Nov 13, 2010 at 10:52 PM
Your issue is that you are using a Namespace with MonoBehaviour which is currently not supported in Unity. I had a similar issue. (see below quote from Unity scripting docs)
http://unity3d.com/support/documentation/ScriptReference/index.Writing_Scripts_in_Csharp.html
5.Don't use namespaces. Unity doesn't support placing your scripts inside of a namespace at the moment. This requirement will be removed in a future version.
Your answer
Follow this Question
Related Questions
Import (mixed assembly) managed C++/CLI DLL plugin 0 Answers
Dll Call Back problem only in Standalone version 0 Answers
Using dll's from C#? 4 Answers
How do you compile a managed dll with mono/mcs targeting .net 2.0 or 3.5 for Unity? 1 Answer
Is there a garantee that managed Dll plugin will compile on to mobile? 0 Answers