- Home /
Method contains unsupported native code
Hi,
I'm currently working on my master thesis and am trying to make everything work in Unity3D. I'm trying to visualize a delaunay tetrahedralization using tetgen software. The point is that tetgen is written in C++. So far, after a lot of effort, I have been able to compile the tetgen source code into a .dll file for use with c# using a c++/cli wrapper. This works fine, that is, untill i try it Unity...
I'm getting the following error: "Method contains unsupported native code". Now, as far as my google-fu goes, this is because the dll is unsafe and recompiling the dll using /clr:safe should fix the problem. That, however, is going to be impossible. So my question is: is it possible to circumvent this problem somehow, or some other way I could go about to solve this problem? I would really like to use Unity, but if I can't integrate tetgen with it, I'm gonna start to look for alternatives. I have already lost a lot of time trying to solve this. Also, I don't have Unity pro (too expensive for just a student).
Thanks in advance,
Sam
Unfortunately, plugins that you create are only supported in the pro version, which of course you have already found out on your own. This requires the namespace 'using System.Runtime.InteropServices;' and a Dll import call from your C# scripts inside Unity. I don't believe there is any other way, and if there is a way, it would probably eat way too much of your time developing it.
So in short, I think you may be SOL unless you can get a copy of Pro, which in case since you've already created a wrapper, should work fairly seamlessly from that point on. For documentation if you haven't already visited it, point yourself to:
http://unity3d.com/support/documentation/$$anonymous$$anual/Plugins.html
There's a student version of Pro for $99, which doesn't allow commercial usage. Seems like a master's thesis should be fine.
@dannyskim : Thank you for your clear and structured answer. I have indeed seen that the pro version can handle plugins better than the indie version can. If you are sure that the pro version can handle dll's containing 'unsafe, unmanaged native' code, I'll try lobbying the university for a license come tomorrow ;). Also, the only examples I've seen using the dll import call in C# are with static external methods. Do you know any good examples where actual classes are imported ins$$anonymous$$d?
Thanks again, you've been very helpful,
Sam
I don't have any examples handy as my work computer isn't with me, but creating JavaV$$anonymous$$'s is a fairly normal practice inside of Android from Unity. I'll see if I can dig something up that is more relevant to your thesis.
Sam did you solve getting TetGen to work with Unity? Can you expand on just how your were able to have been able to compile the TetGen source code into a .dll file for use with c# using a c++/cli wrapper? How about posting it in the asset store?
Answer by sirbrialliance · Feb 27, 2014 at 12:55 AM
Mono (which unity uses) does not support mixed-mode assemblies.
You can use C++/CLI if you use 100% managed code with the right compiler options.
Instead, you can write a C (or C++ with the right mangling options) DLL and access it via P/Invoke.
Also, plugins are only supported in the Pro version.
Thanks! I already solved the issue a couple of years ago. I got a temporary license and used P/Invoke like you said.