I am using C++ plugins and passing out array ptrs in my function. Unity 5.6 keeps complaining about unsafe code. I added every type of .rsp file with the "-unsafe" keyword, but none of it works. Anyone figure this out for unity 5.6?

  • 2
    \$\begingroup\$ .. Does it tell you what is unsafe? \$\endgroup\$ – Gnemlock Jun 13 '17 at 8:49
  • \$\begingroup\$ Switch to 2017 beta :-) full net 4.6 suppory, nut experimental so keep a backup :-) \$\endgroup\$ – John Demetriou Jun 13 '17 at 12:33

Are you sure that unsafe code cannot be enabled?

  • You must create the file mcs.rsp (with -unsafe inside of the file).

  • You must also change Api Compatibility level to .net 2.0 subset

  • Restart both Unity/Visual Studio to make it work.

(See this answer for a detailed explanation)

However, if none of these works, there is another (untested) way.

  • Create a .net dll, compiled with unsafe flag (Tick "Allow unsafe code" in VS Project Settings)

  • Place your unsafe code in that dll

  • Then just call your unsafe function from Unity

    Please note this is untested and is better to try the 1st way

In any case, make sure your function has the unsafe keyword at the definition:

 public unsafe intPtr myUnsafeFunction() // just an example

Or wrap your unsafe code with unsafe { }

 unsafe {
      // your unsafe code

Hope that helps


Not the answer you're looking for? Browse other questions tagged or ask your own question.