- Home /
How to enable unsafe and use pointers
I am trying to use some pointers in my code. And i get this error in monodevelop:
Parse error: unsafe code requires the 'unsafe' command line option to be specified
When you're creating the file "smcs.rsp" do you create a new C# file?
Answer by Bunny83 · Oct 06, 2014 at 04:47 PM
I strongly recommend to not use pointers and unsafe code at all. Keep in mind that some platforms don't support unsafe code for safety such as the webplayer for example.
If you really need an unsafe context, you have to create a "smcs.rsp" file in your asset folder and add the line
-unsafe
to that file. This should add this parameter to the c# compiler options when compiling your project.
Again, using unsafe doesn't give you much advantages, it just opens up for a huge variety of errors, mistakes and unexpected behaviour. Unless you know exactly what you do and you use pointers sparsely you shouldn't go for an unsafe context.
I am probably doing something wrong, but i tried twice and when i create "smcs.rsp" file in my Assests folder and put that one line nothing changes. What am i missing?
Restarted unity and everything is working right now, thanks!
$$anonymous$$ake sure this file is at the top level of Assets (i.e. Assets/smcs.rsp)
smcs.rsp
should be used with .Net API Compatibility Level 2.0 Subset (Build Settings)
When using the full .Net 2.0 compatibility level, the file has to be named gmcs.rsp
ins$$anonymous$$d
Having done so, I still get an error when debugging in $$anonymous$$onodevelop. It seems that whenever you enable the option 'allow unsafe code' in $$anonymous$$onodevelop unity just overwrites this next time you start monodevelop. Any ideas?
This line:
when targeting $$anonymous$$S compiler, csc is used with csc.rsp, etc.
at
https://docs.unity3d.com/$$anonymous$$anual/PlatformDependentCompilation.html
may be important to notice... I had to add that file too, so code could be exported to Visual Studio.
Answer by wyb314 · Sep 29, 2015 at 09:13 AM
In BuildSetting ,you should changes to the "Api Compatibility Level" to" .NET 2.0 Subset" yet.
Answer by jasons-novaleaf · Jan 04, 2021 at 02:42 PM
New answer
(tested in 2020.2)
You can go to Project Settings --> Player and at the bottom under "Script Compliation" there is a checkbox for "Allow 'unsafe' Code"
Your answer
![](https://koobas.hobune.stream/wayback/20220613164518im_/https://answers.unity.com/themes/thub/images/avi.jpg)