technical architecture.

Unity per project compiler options, -unsafe

by on Nov.28, 2011, under csharp, Unity3D

I had to integrate a small set of third party code that calls down to some win32 dllimport bits, to do this I needed to be able to work with some pointers. which in c# need to be declared in an unsafe function, so that it knows to be unmanaged.

Slightly awkward, but it turns out that there is an -unsafe compiler option that needs to be turned on in unity/mono, and that you can do this very easily on a per project basis by adding a file ‘smcs.rsp’ to the root of your assets dir, and in there you can add the text ‘-unsafe’ to add this to the compiler commandline.

Reference threads: Setting Compiler Options, Unsafe code in Unity, How To: Set Project-Wide #pragma Directives with JavaScript

Other apparent uses stated in the threads are setting project wide defines and pragmas

3 Comments for this entry

  • Dave Buchhofer

    you may need to place the compiler flags into the ‘Assets/gmcs.rsp’ instead, it seems to vary by project?

  • VDZ

    Thank you very much for this solution, it was exactly what I was looking for.

  • Random

    More info: different compilers are used based on the language and chosen .NET profile. The subset and web profiles use smcs, the full profile uses gmcs, unityscript uses us, and boo uses booc.

Leave a Reply

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!