Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unity3D Unsafe code requires the `unsafe' command line option to be specified

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?

like image 241
or azran Avatar asked Jul 01 '14 14:07

or azran


People also ask

How do I allow unsafe code unity?

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.

What is unsafe code C#?

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.

How do I allow unsafe code in Visual Studio?

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."

How to enable “unsafe” in Unity?

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.

How do I return an error from the command line Unity?

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.

How do I run Unity from the command line?

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.

What happens when an exception occurs in Unity?

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.


2 Answers

Go to your project properties page and check under Build the checkbox Allow unsafe code. This should solve your problem.

like image 69
CodeTherapist Avatar answered Oct 15 '22 06:10

CodeTherapist


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.
enter image description here

like image 37
us_david Avatar answered Oct 15 '22 07:10

us_david