- Home /
Can i import already compiled code into Unity and then call functions in it?
I have some c# code , which uses some things which dont work in unity, like .NET 4.0 , so i can only compile it outside of unity. Is there a possibility to import that into unity and call some funktions in the code? Maybe make unity start the exe and then send and recieve data from it? or import it as Dll?
Answer by tanoshimi · Aug 19, 2016 at 02:14 PM
Of course - just drag the compiled DLL into your project like any other asset and you can call into its functions as usual: https://docs.unity3d.com/Manual/UsingDLL.html
In that case, no (might have been useful for you to state that in your original question....). I believe there is a possible workaround for you to export the library as an "unmanaged export" and then Unity will treat it as a native plugin rather than a managed plugin, but haven't tried it myself: https://sites.google.com/site/robertgiesecke/Home/uploads/unmanagedexports
Answer by Flamio · Aug 19, 2016 at 02:22 PM
Import as DLL will help you. But it must be compiled in .NET 2.0.
Unity doesnt support .Net 4.0
It pretty much still uses 2.0 with some 3.5 support thrown in.
2.0.50727.1433 to be exact, according to Debug.Log(System.Environment.Version);
i know, thats why i had the idea to load precompiled code. Unity should ignore what it is in the fuction and only deliver parameters and read the return value.
Your answer
Follow this Question
Related Questions
unity allow player to script a object or compile and run a code in runtime 1 Answer
Why can't I build Web Player in Unity while I have no problems with building standalone versions? 2 Answers
Import (mixed assembly) managed C++/CLI DLL plugin 0 Answers
"Copying dll file: access denied" while importing a package 1 Answer
Multiple usage of import System.Xml; in different scripts, same scene? 1 Answer