Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
4
Question by doubstract · Oct 06, 2014 at 03:49 PM · unsafe

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

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image ohw979 · Feb 19, 2017 at 11:05 PM 0
Share

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

3 Replies

· Add your reply
  • Sort: 
avatar image
7
Best Answer

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.

Comment
Add comment · Show 6 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image doubstract · Oct 06, 2014 at 06:49 PM 0
Share

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?

avatar image doubstract · Oct 06, 2014 at 08:29 PM 0
Share

Restarted unity and everything is working right now, thanks!

avatar image Xorxor · Feb 25, 2016 at 07:05 AM 0
Share

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

avatar image asafsitner · Mar 21, 2016 at 04:05 PM 2
Share

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

avatar image jpfranssen asafsitner · Apr 07, 2016 at 07:17 AM 0
Share

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?

avatar image pfiguero · Jul 21, 2016 at 01:01 AM 0
Share

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.

avatar image
1

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.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
1

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"

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

13 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Compiler options, unsafe 2 Answers

How to implement custom Native List 1 Answer

Associating NativeArray with a Job manually 1 Answer

Trouble creating a C# UDP interface to a C++ app in Unity 2 Answers

NativeList.GetUnsafePtr() throwing The type 'T' must be a non-nullable value type 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges