2
\$\begingroup\$

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?

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

1 Answer 1

2
\$\begingroup\$

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

\$\endgroup\$

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.