Is there any Unity-specific reason that we should avoid unsafe code for pointers etc?
I've enabled unsafe compilation for csharp in the compiler options and everything seems to work OK - just wanting to make sure
Thx
shaun
Unity Community |
Is there any Unity-specific reason that we should avoid unsafe code for pointers etc?
I've enabled unsafe compilation for csharp in the compiler options and everything seems to work OK - just wanting to make sure
Thx
shaun
If you want to publish to the web player you should not use unsafe code as it will be disabled. If you are only doing standalone, thats fine.
Joachim Ante
I guessed that might be the case. Thanks
Can u tell me please how do you enable unsafe compilation in the compiler options?
Thanks a lot,
Tomas![]()
Firstly show the contents of Unity.App and drill down to Contents/Frameworks/MonoCompiler.framework.
Open the file called compile_any.pl and in the section "# Run the csharp compiler" change @Base_Args options as below:
Code:
my @base_args=($mono_path, $mcs_path, '-debug', '-unsafe', '-target:library', '-nowarn:0169', '-out:'.$output, );
Cheers
Shaun
Is it still possible to run unmanaged code in stand-alone applications? Because i just tried to manipulate the compile-all.pl file as described, but doing so has no effect at all. Even deleting the script does not hinder Unity to compile scripts. Is there any other way to specify additional compiler command line options?
Hi I'm also looking for an answer to this... any news on a solution?
Cheers,
I think you can use unsafe code with C#, but you need the pro license of the engine.
As the changes to that file affect the parameters passed to the mono compiler you'll likely need to force all of your scripts to recompile (I do this using the 'touch' command from osx/cygwin on each file to update its modification times).
Not sure what your environment might be like, but any way of updating the modification time of the files (like modifying them for example) will make that happen.
"Order and Protection. In order that they may rot in comfort." - Miller
I am wondering how to make this change in Unity 3.0 Pro (Windows platform). Any ideas?
Last edited by Sprocket; 11-06-2010 at 07:28 AM.
Unity Pro supports unsafe code in all its various guises. Unsafe code does not work with the web player due to security reasons.
Silly distractions
Wednesday Thursday Friday Saturday Sunday Monday
Useful Things
OtakuNoZoku Justin Lloyd Infinite Monkey Factory @JustinLloyd
to be more precise about webplayer: Anything relying on P/Invoke is disabled and cut, not only unsafe code
Whilst that is true, the OP was asking specifically about unsafe code. We could go in to a long dissertation about what is and isn't possible in the web player, including speed and performance differences, and all it would do is muddy the point that the OP wanted to know if unsafe code is possible in Unity.
Silly distractions
Wednesday Thursday Friday Saturday Sunday Monday
Useful Things
OtakuNoZoku Justin Lloyd Infinite Monkey Factory @JustinLloyd
You can try using smcs.rsp/gmcs.rsp
Basically add a file inside Assets/ called smcs.rsp/gmcs.rsp (It seems to be different per person). Inside that file you can add custom compiler commands, such as includes, defines, or flags. I've tested both defines and warnings as errors flag and they work. All you would need to do in there is add -unsafe.
The thread that lead me that file was:
http://forum.unity3d.com/threads/714...ith-JavaScript
And it should have enough info to start testing it out.