How to enable unsafe and use pointers
Asked Answered
L

3

0

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

Liquidambar answered 6/6, 2023 at 2:9 Comment(1)

When you're creating the file "smcs.rsp" do you create a new C# file?

Bronwynbronx
S
0

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.

Saucedo answered 6/6, 2023 at 2:6 Comment(5)

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?

Liquidambar

Restarted unity and everything is working right now, thanks!

Liquidambar

Make sure this file is at the top level of Assets (i.e. Assets/smcs.rsp)

Popham

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 instead

Simpleminded

This line: when targeting MS compiler, csc is used with csc.rsp, etc. at https://docs.unity3d.com/Manual/PlatformDependentCompilation.html may be important to notice... I had to add that file too, so code could be exported to Visual Studio.

Bor
P
0

In BuildSetting ,you should changes to the “Api Compatibility Level” to" .NET 2.0 Subset" yet.

Putup answered 29/9, 2015 at 9:13 Comment(0)
R
0

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”

Richmond answered 6/6, 2023 at 2:35 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.