Allow unsafe code for editor scripts only

Hello everyone,
Is there a way to enable unsafe code for the editor scripts only? I am creating an extension and need to use unsafe code, however, I don’t want to use it in the actual game project.

I will be converting all the created editor scripts to a DLL file and will turn all that into a custom package.

Is there some way to allow the usage of unsafe code in the editor scripts without the need of enabling the option in PlayerSettings for the entire project? Because I know that some platforms do not support unsafe code, such as web players, and disabling the option will raise errors in editor scripts.

You might “hard code” it by simply checking if you’re using the editor before calling the unsafe code, but apart from that I personally don’t know of anything.

If you use assembly definition files then you can specify allow unsafe per each.

2 Likes