Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Allow unsafe code for editor scripts only

Discussion in 'General Discussion' started by UserNobody, Aug 29, 2021.

  1. UserNobody

    UserNobody

    Joined:
    Oct 3, 2019
    Posts:
    144
    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.
     
  2. EternalAmbiguity

    EternalAmbiguity

    Joined:
    Dec 27, 2014
    Posts:
    3,144
    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.
     
  3. steego

    steego

    Joined:
    Jul 15, 2010
    Posts:
    968
    If you use assembly definition files then you can specify allow unsafe per each.
     
    UserNobody and JoNax97 like this.