Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

[Feature request] Precompile directives for build-in packages

Discussion in 'Package Manager' started by Grumpy-Dot, May 26, 2019.

  1. Grumpy-Dot

    Grumpy-Dot

    Joined:
    Feb 29, 2016
    Posts:
    93
    Hello,

    I would really love to see precompile directives corresponding to Unity's built-in packages.
    This will allow me to easily share the same libraries between the projects, even if they have different requirements.

    Let's say I have some scripts that use the Rigidbody class, I can just wrap them in #if UNITY_PHYSICS_PACKAGE ... #endif and they won't raise errors if I disable the Physics module.

    I am aware that I could write my own system of precompile directives, but having this provided by the Package Manager would make things more neat.

    Let me know what you think. ;)
     
    brunocoimbra and mobuni5 like this.
  2. brunocoimbra

    brunocoimbra

    Joined:
    Sep 2, 2015
    Posts:
    679
    +1 on that, I needed to write my own system of precompile directives to make my framework work across different projects without needing to split it into many smaller packages, having that built-in would be really welcome!
     
    Grumpy-Dot likes this.
  3. okcompute_unity

    okcompute_unity

    Joined:
    Jan 16, 2017
    Posts:
    756
    Hi @Grumpy-Dot and @brunocoimbra , I believe this feature already exists in the *Assembly Definitions* inspector. Look for the *Version Defines* section:



    Regards,

    Pascal
     

    Attached Files:

    mobuni5 and Grumpy-Dot like this.
  4. Grumpy-Dot

    Grumpy-Dot

    Joined:
    Feb 29, 2016
    Posts:
    93
    Hello, thank you for the suggestion!
    I found nothing in the documentation related to Version Defines section, but I've quickly tested it and it seems to work as expected.
    Unfortunately, this forces us to create and use the Assembly Definitions, which can be a bit of pain, especially if you have a lot of Editor folders.
    Nevertheless, this is a good option for a library, and it gives you the flexibility of having defines based on the version of the module.
     
  5. okcompute_unity

    okcompute_unity

    Joined:
    Jan 16, 2017
    Posts:
    756
    @Grumpy-Dot , Yes I was also surprised this feature is not documented. It is available since 2019.1.

    I don't understand what you mean. As far as I know, assembly Definition files are required if you want to include scripts in a package. And you can merge/move all your code under one assembly definition file if you want. Though it is always a better practice to modularize your code this is not a strict requirement.

    Regards,

    Pascal
     
  6. brunocoimbra

    brunocoimbra

    Joined:
    Sep 2, 2015
    Posts:
    679
    Thank you so much! Didn't realize what that section was for, so glad this feature is there!
     
  7. Grumpy-Dot

    Grumpy-Dot

    Joined:
    Feb 29, 2016
    Posts:
    93
    I was not planning to include the scripts in a package, the 'library' that I'm working on now is just a simple git submodule that I use to share useful scripts between my unity projects.
    It also contains packages from other developers, most of them do not have assembly definition files and they got plenty of Editor folders. So if I want to add the assembly definition files myself, I have to maintain it and do it again if the authors update their plugins.
    But at least for my own code, this is feasible and will bring modularity, like you said.
    Thanks again for all the help!
     
    okcompute_unity likes this.