Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Unity free, plugins and native DLLs

Discussion in 'Scripting' started by alexzzzz, May 8, 2013.

  1. alexzzzz

    alexzzzz

    Joined:
    Nov 20, 2010
    Posts:
    1,447
    Everyone knows that plugins are only supported in Unity Pro. It's also a common knowledge here (on Forums and Answers) that if you have a native dll, you have to put it in Plugins folder and own the Pro license to be able to use it. Actually this knowledge is wrong, at least on Windows. The documentation states that plugins are native libraries, but it doesn't state that every native library is a plugin. So, you can call functions from native libraries without the Pro license.

    1. Download the standard plugin example from here.
    2. Run it using free Unity and get the error "License error. Plugins are only supported in Unity Pro!"
    3. Move the dll from Project/Assets/Plugins to just Project/.
    4. Run it again and get no errors. It works fine.
    5. Make a standalone build, copy the dll to where the executable is, and it will work too.
     
    Last edited: Aug 12, 2014
  2. exiguous

    exiguous

    Joined:
    Nov 21, 2010
    Posts:
    1,749
    thanks for the info. i have filed a bug report.
     
  3. angrypenguin

    angrypenguin

    Joined:
    Dec 29, 2011
    Posts:
    15,614
    Are you sure the example gives a native code plugin? I was under the impression that C# assemblies worked in Unity Free.
     
  4. exiguous

    exiguous

    Joined:
    Nov 21, 2010
    Posts:
    1,749
    as the given example contains cpp files it is native code. the inlcuded c# file only calls the plugin. i have no unity free installed (and no c++ environment) to test and verifiy this but the given explanation sounds reasonable and could be a bug which can be exploited.
     
  5. alexzzzz

    alexzzzz

    Joined:
    Nov 20, 2010
    Posts:
    1,447
    First I tried it with my own native dll and it worked, then I checked the standard plugins example, it worked too. So, I have no doubts. I don't think it's a bug for several reasons.

    1. It's been there for ages. Just rechecked with Unity 3.0 and it works.

    2. Platform invoke is a standard net/mono functionality and I expect it to work unless the opposite is stated explicitly. Just like accessing managed libraries you've mentioned.

    3. Mono is not a UT's product. I believe it would be a kind of dirty trick to cut off a part of someone else's free product and then sell this part back for money. Either you support the feature or you don't, with no money conditions attached.

    4. Platform invoke is the only way to call WinAPI. For example, if you want to show a MessageBox you have to call a function from "user32.dll" which is definitely not a plugin for Unity. If any calls to native libraries other than libraries in Plugins folder were prohibited, you would have to create a native wrapper library around the native Windows library to be able to access the MessageBox function from your managed code. It sounds like a stupid waste of time and effort to me. Why not just call it directly?
     
    Last edited: May 9, 2013
  6. alexzzzz

    alexzzzz

    Joined:
    Nov 20, 2010
    Posts:
    1,447
  7. alexzzzz

    alexzzzz

    Joined:
    Nov 20, 2010
    Posts:
    1,447
    Any updates yet on your bug report?
     
  8. exiguous

    exiguous

    Joined:
    Nov 21, 2010
    Posts:
    1,749
    No. you can follow it here.
     
  9. alexzzzz

    alexzzzz

    Joined:
    Nov 20, 2010
    Posts:
    1,447
  10. ZJP

    ZJP

    Joined:
    Jan 22, 2010
    Posts:
    2,649
    Yes.
    Have a look on my signature. I've a TTS DLL that works with Unity indie since 2010.

    The "System.Runtime.InteropServices" was disabled by UT in the past. :(
     
  11. PabloJMartinez

    PabloJMartinez

    Joined:
    Feb 7, 2013
    Posts:
    21
    Nice, would this work with KopiLua and KopiLuaInterface?

    Thanks.
     
  12. zezba9000

    zezba9000

    Joined:
    Sep 28, 2010
    Posts:
    985
    I don't understand why Plugins for desktop platforms are not free. I mean there are just to many ways to get around it anyway.
    You could even recompile Mono to force features on. Just seems like a waste of time to try and lock people out of this.
    It seems like both parties would benefit from making it free anyway. As I could make Desktop plugins for Free users, which add up to more sales on the Asset store and more money for everyone...
     
  13. gfoot

    gfoot

    Joined:
    Jan 5, 2011
    Posts:
    550
    KopiLua is managed, you don't need native DLLs for it to work - it's fine on Unity Basic, as well as on mobile and in the webplayer.

    BTW I updated it a lot recently - it's more stable now.
     
  14. alexzzzz

    alexzzzz

    Joined:
    Nov 20, 2010
    Posts:
    1,447
    I believe the plugins are just not that thing most people think they are, not just native dlls, but kind of special dlls that use native plugin interface. All the other native dlls are not plugins and therefore should work fine in Unity Free. Unfortunately, the docs are kind of foggy.
     
  15. remigillig

    remigillig

    Joined:
    Jul 4, 2013
    Posts:
    9
    Why report a bug!? If they know about it they might cut it now...

    Same here, XInput.NET (P/Invoke style plugin) has been working fine for me since Unity 2.5 (2009).
     
  16. exiguous

    exiguous

    Joined:
    Nov 21, 2010
    Posts:
    1,749
    they should cut it. when software behaves not as expected it is a bug. and beeing able to do something in unity free which should be limited to pro is not "working as expected" albeit some people may benefit from it.
    some potential downsides:
    UT loses some money because people don't upgrade to pro when they can use it's features freely
    people who payed for these features are annoyed
    exploiting this bug could get you in legal issues

    i have no clue about eula and laws but i think it's important for UT to know what can be done. thats why i filed the bugreport. now they can handle it to their liking, which includes to simply ignore it.
     
  17. remigillig

    remigillig

    Joined:
    Jul 4, 2013
    Posts:
    9
    Sure, I was half joking. I think it's a good thing to be able to use P/Invoke to make plugins for the Free version. However I wouldn't mind paying for this feature as well. It's just that if you make plugins, you usually want people to be able to use them. I don't know the split between Free/Pro between Unity users but having a plugin support both makes it more visible.

    EDIT: for example I can use UnityVS in the Free version, and that's awesome for both Unity Technologies and developers
     
  18. zezba9000

    zezba9000

    Joined:
    Sep 28, 2010
    Posts:
    985
    -- The thing is time is money, and the fact is its not possible to stop people from using pInvoke in Mono, as Mono libraries must be open as there under GPL and so I can recompile them if I wanted to and force Unity to enable pInvoke no matter what they turn off.
    Its a waste of time and money to even disable plugins for desktops because of this simple fact. It also looses money in asset store sales for people that can't buy a plugin because its pro only. And makes it hard for me as a plugin developer to target that crowd.
     
  19. sfernandez

    sfernandez

    Joined:
    Feb 14, 2012
    Posts:
    104
    In fact, Unity loses money because of limiting native plugins to Unity Pro too, because many assets sold in store will be only available for people owning a Pro license.

    I've started a new feedback query about this, feel free to vote for it: Allow Native Code Plugins in Unity Free
     
  20. zezba9000

    zezba9000

    Joined:
    Sep 28, 2010
    Posts:
    985
    Cool voted. Ad block seems to block me from voting, had to turn it off for the Unity pages.
     
  21. remigillig

    remigillig

    Joined:
    Jul 4, 2013
    Posts:
    9
    10 votes ! This is a great idea, thanks for creating the query :)
     
  22. alexzzzz

    alexzzzz

    Joined:
    Nov 20, 2010
    Posts:
    1,447
    We have different expectations. A simple question: where is it stated that native dlls are plugins, where does this idea come from? I can't find any traces.

    By the way, does everyone know that Unity supports unsafe C# code? The stuff like allocating local arrays on stack, pointer arithmetics, using memory from unmanaged heap. It's turned off by default (like in Visual Studio and MonoDevelop), but you can turn it on if you want. It's not a widely known feature, but not a hidden one either.
     
    Last edited: Oct 2, 2013
  23. zezba9000

    zezba9000

    Joined:
    Sep 28, 2010
    Posts:
    985
    This is why making plugins via a library is a better idea. You can use unsafe if you need to.
    You can also link to libs Unity doesn't add the the CS projects for you like, "System.XML.Linq'.
     
  24. alexzzzz

    alexzzzz

    Joined:
    Nov 20, 2010
    Posts:
    1,447
    Managed libraries are definitely not plugins. Some guys on Asset Store put their dlls in Plugins folder, but that's just wrong.

    And you don't need managed libraries to be able to use unsafe code. Just add "-unsafe" as an option for C# compiler in Unity.
     
  25. zezba9000

    zezba9000

    Joined:
    Sep 28, 2010
    Posts:
    985
    I know, but its nice if your handing out a plugin backed by a pre build lib, as they don't have to take any extra steps.
     
  26. angrypenguin

    angrypenguin

    Joined:
    Dec 29, 2011
    Posts:
    15,614
    I also believe that "unsafe" mode doesn't work on some mobile platforms, but I could be wrong there as I've never checked.

    Also, sticking managed DLLs in the Plugins folder may have more to do with compilation order than about it strictly being a plugin.
     
  27. zezba9000

    zezba9000

    Joined:
    Sep 28, 2010
    Posts:
    985
    Unsafe works on every mobile platform: Win8, WP8, iOS, Android and BB10.
     
  28. Wonka45v

    Wonka45v

    Joined:
    Dec 19, 2014
    Posts:
    8
    So how would i implemented this unsafe, to lets say steamworks.net plugin?
     
  29. zezba9000

    zezba9000

    Joined:
    Sep 28, 2010
    Posts:
    985
  30. Wonka45v

    Wonka45v

    Joined:
    Dec 19, 2014
    Posts:
    8
    Will this turn all my code to unsafe? If it does will it affect anything?
    What about the plug-in itself (steamworks.net)? Do i have to put it in plug ins folder?
     
  31. zezba9000

    zezba9000

    Joined:
    Sep 28, 2010
    Posts:
    985
    No it will not turn all your code to unsafe. People take this word out of context in .NET.
    All it means is you have the ability to use "unsafe" code blocks. If you don't use that keyword in your code you can't write any "unsafe" code.

    NOTE: "unsafe" doesn't mean the code is necessarily unsafe, that would be calling all C++ code unsafe which is just silly (even managed code can be unsafe). It just lets you access and write code thats closer to native code and makes working with C code super easy at times.
     
  32. Kirk Clawson

    Kirk Clawson

    Joined:
    Nov 4, 2014
    Posts:
    65
    Unsafe is indeed a poor choice for that compiler option and keyword. It doesn't mean that your code is now somehow magically more hackable, or that it will melt a cell phone's battery. A better name for the compiler option would probably have been -allowUnManaged, used in conjunction with unmanaged {} code blocks. But alas, we use the word "unsafe" to mean both.
     
    vexe and zezba9000 like this.
  33. zezba9000

    zezba9000

    Joined:
    Sep 28, 2010
    Posts:
    985
    Ya some keyword like "unmanaged" or "native" would have been better.
    Personally I think "native" is the best keyword as you can still use unamanged memory without .NET "unsafe" blocks via Marshal. Thus native makes sense as thats exactly what your doing in concept, developing native code logic embedded in .NET just like you can use "asm" blocks in C/C++.
     
  34. alexzzzz

    alexzzzz

    Joined:
    Nov 20, 2010
    Posts:
    1,447
    smcs.rsp is for .Net 2.0 Subset. If .Net 2.0 is selected, the file must be named gmcs.rsp.
     
    zezba9000 likes this.
  35. Shizen

    Shizen

    Joined:
    Dec 31, 2012
    Posts:
    14
    This may seem a little off topic, but I've been looking at the options for Unity builds more and more recently as my projects have become increasingly larger. I have a lot of framework projects, but Unity provides no automated facility for including project dependencies, etc. between Unity Projects (that I know of, at least). There isn't even any pre/post build action system that I've found.

    Anyway, pertinent to this discussion, are you guys saying that DLLs built incorporating the unity dlls won't work from the assets folder (I've never tested that, tbh)? Or do you literally mean only if you are going to subscribe to the low-level events interface provided by the plugin api (which is only relevant to mobile devices)?

    Conceivably, one could build a subscriber system where you compiled your Unity frameworks in VS or mcs or whatever with a post action to move it to all subscribing Unity Projects' asset folder. A PITA to be sure, but doable. Of course, this entire conversation ignores the another advantage of the plugins folder, which is by device target inclusion.
     
  36. vexe

    vexe

    Joined:
    May 18, 2013
    Posts:
    644
    I assume that implies that 'fixed' also work on mobile?
     
    Last edited: Mar 1, 2015
  37. zezba9000

    zezba9000

    Joined:
    Sep 28, 2010
    Posts:
    985
    Yes if you can use unsafe code you can use fixed. The only platform its not going to work on is Playstation Vita with PSM.
     
    vexe likes this.
  38. MathewHI

    MathewHI

    Joined:
    Mar 29, 2016
    Posts:
    501
    Are native plugins still only for Unity Pro or has that been changed now? I don't see anything in the manual about them being version specific. I think they might be free now.
     
  39. MathewHI

    MathewHI

    Joined:
    Mar 29, 2016
    Posts:
    501
    Indeed they are free sir. I just wrote a native plugin myself in Unity Free.