i am using Unity3D 4.3
and calling a DLL
that i created.
when trying to call the only function it have which is this:
void GetModelReferences(int &nVertices, float * vertices, int &nTriangles, int * triangles, float * normals, float * uvCoordinates);
unity gives me an error:
Unsafe code requires the `unsafe' command line option to be specified
so in my MonoDevelop
i opened : Project->Assembly-Csharp options
and turned on the unsafe
mode.
it reduces part of the errors but this last one wont go away
Unsafe code requires the `unsafe' command line option to be specified
what shoud i do?
Create a file in your <Project Path>/Assets directory and name it smcs. rsp then put -unsafe inside that file. Save and close that file. Close and reopen Visual Studio and Unity Editor.
Unsafe code in C# is the part of the program that runs outside the control of the Common Language Runtime (CLR) of the . NET frameworks. The CLR is responsible for all of the background tasks that the programmer doesn't have to worry about like memory allocation and release, managing stack etc.
To set the unsafe option in Visual Studio 2012, click on Project in the main menu, select the Build pane, and check the box that says "allow unsafe code."
Enabling “unsafe” for unity c# is quite simple: – Add these 2 files to your project folder (inside Assets/ folder root) – “smcs.rsp” and “gmcs.rsp”. – both files contain only 1 line of text: -unsafe. – Then restart Unity and VisualStudio/Monodev.
To return an error from the command line process, either throw an exception which causes Unity to exit with return code 1, or call EditorApplication.Exit with a non-zero return code. To pass parameters, add them to the command line and retrieve them inside the function using System.Environment.GetCommandLineArgs.
You can run Unity from the command line (from the macOS Terminal or the Windows Command Prompt). On Windows, type the following into the Command Prompt to launch Unity: When you launch Unity like this, it receives commands and information on startup, which can be very useful for test suites, automated builds and other production tasks.
When an exception occurs during execution of the script code, the Asset server updates fail, or other operations fail, Unity immediately exits with return code 1. Note that in batch mode, Unity sends a minimal version of its log output to the console.
Go to your project properties page and check under Build
the checkbox Allow unsafe code
.
This should solve your problem.
Here is what worked for me with Unity3D 5.3:
- If in your Unity Build Setting->Player Setting->Other Settings, "API Compatibility Level" is ".Net 2.0", create a file under your Unity Asset folder called gmcs.rsp, add this following line to the file:
-unsafe
Close Unity and open it again.
- If the "API Compatibility Level" is ".Net 2.0 Subset", the above file name should be: smcs.rsp.
See the picture bellow to find the location of ""API Compatibility Level" setting in Unity.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With