Search Unity

  1. Check out our Unite Austin 2017 YouTube playlist to catch up on what you missed. More videos coming soon.
    Dismiss Notice
  2. Unity 2017.2 is now released.
    Dismiss Notice
  3. The Unity Gear Store is here to help you look great at your next meetup, user group or conference. With all new Unity apparel, stickers and more!
    Dismiss Notice
  4. Introducing the Unity Essentials Packs! Find out more.
    Dismiss Notice
  5. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice
  6. Unity 2017.3 beta is now available for download.
    Dismiss Notice

How to use custom compiled c# dlls or assemblies?

Discussion in 'Scripting' started by Abdullah.Ahmed, Oct 16, 2009.

  1. Abdullah.Ahmed

    Abdullah.Ahmed

    Joined:
    Sep 22, 2009
    Posts:
    18
    Hey guys,

    I have a few questions regarding Unity and custom assemblies...

    1- Is it possible for me to create my own assembly in C# (say using Visual Studio or MonoDevelop) and then reference that assembly, its classes and functions within unity C#/Javascript scripts?

    2- How would I go about using a custom .dll in these scripts?

    3- Are there any limitations to such dlls? Do I have to compile for a certain .net framework? (such as 1.1, 2.0 etc).
     
  2. mmwizard

    mmwizard

    Joined:
    Mar 27, 2009
    Posts:
    65
  3. zumwalt

    zumwalt

    Joined:
    Apr 18, 2007
    Posts:
    2,202
    Forget the plugins.html for this, if you write a C# library, you simply use it in Unity by dragging the C# dll into your assets folder, you only need the Plugins folder if you are going to use a C++ library. You can use C# DLL's with Indy version of Unity and can skip the plugins all together.

    All you have to do is add a
    using YourNamespace;
    At the top of your CS file, then call your methods like you would call any other method in Unity. Just take care to compile your project / class file for Framework 2.0, you can't use System.Windows or System.Windows.Forms components, you do have some framework limitations but you will find those as you go along.

    Using C# libraries are cake, oh and you can't use anything made with SWING in Unity either, the P/Invoke isn't cross platform compatible.
     
    RobertoLangarica likes this.
  4. Abdullah.Ahmed

    Abdullah.Ahmed

    Joined:
    Sep 22, 2009
    Posts:
    18
    Awesome, thanks!

    The questions may have been silly but they were a conceptual roadblock for me. I think knowing that I can pretty much use most of the power of the .net framework really makes Unity's potential exciting for me.
     
  5. fletch27502

    fletch27502

    Joined:
    Sep 2, 2010
    Posts:
    9
    I have some C# managed dlls that I've placed into the Assets folder, and I'm getting an Internal Compiler Error.

    I'm using Unity 2.6, and my target platform is Windows only. Any help would be appreciated.

    Thanks,
    Scott
     
  6. tstpierre

    tstpierre

    Joined:
    Jun 21, 2011
    Posts:
    7
    What's the console output say? Any exception being written?