Search Unity

Feature Request Preprocessor directives for editor modules such as iOS build support?

Discussion in 'Editor & General Support' started by Xarbrough, Jan 25, 2021.

  1. Xarbrough

    Xarbrough

    Joined:
    Dec 11, 2014
    Posts:
    1,188
    Accessing e.g. UnityEditor.iOS.Xcode is only possible when the iOS build support module is installed in the editor. If it's missing, code within the namespace doesn't compile.

    To tackle this issue, I wrap iOS-specific code in the UNITY_IOS preprocessor directive as documented in the Platform Dependent Compilation feature.

    However, this has issues:
    • UNITY_IOS is only defined when the platform is set to iOS, however, I'd like to detect if the iOS build support module is installed, not the platform. Especially when working on build workflow systems, I only care about setting up the environment that will run on other computers.
    • Such code will not compile on other platforms which can cause refactoring issues. For example, I develop my build system on Windows, write code for Android and iOS, which is similar and will compile fine if the build support is installed. But because other developers on the team don't have the build support installed, I need to use the platform flag to prevent issues. Now it's possible to accidentally break the code for iOS if I refactor/rename a method while on Android platform.
    I suggest adding preprocessor directives for modules so that editor tooling can check platform and modules separately. :)
     
    Last edited: Sep 16, 2021
  2. HWIvan

    HWIvan

    Joined:
    Jan 21, 2019
    Posts:
    12
    Yeah this is sorely needed for writing packages that you want to add support for multiple platforms to, but only if the user has installed the platform.
     
  3. Rotary-Heart

    Rotary-Heart

    Joined:
    Dec 18, 2012
    Posts:
    813
    While this is by no means an official preprocessor, you can add your own checking if the directory exists in a [InitializeOnLoad] editor script.
     
    Xarbrough likes this.