Search Unity

Optional package dependencis?

Discussion in 'Package Manager' started by jwvanderbeck, Jul 31, 2019.

  1. jwvanderbeck

    jwvanderbeck

    Joined:
    Dec 4, 2014
    Posts:
    535
    I had posted this earlier in the general editor forum, but it was suggested I post it here instead. Original post follows :)

    How can I set up something so that one package depends on and uses another package but only if that other package is present. In other words that second package is optional and extends functionality if present. If it is not present, the first package can still run without it.

    The "old" way I could do this using #define conditionals, but with packages it seems more complicated because you have to define the dependencies
     
  2. maximeb_unity

    maximeb_unity

    Unity Technologies

    Joined:
    Mar 20, 2018
    Posts:
    121
    Hi @jwvanderbeck,

    Please take a look at the Version defines section of https://docs.unity3d.com/Manual/ScriptCompilationAssemblyDefinitionFiles.html. I think it should do what you want. You do not need to define a dependency in the package.json, otherwise the dependency will not be optional (as you have probably guessed).
     
  3. jwvanderbeck

    jwvanderbeck

    Joined:
    Dec 4, 2014
    Posts:
    535
    Hi, thanks for the reply. I did read that section but to be honest it didn't completely make sense to me. Maybe I need to revisit it and just play with it in the editor to see what happens.
     
  4. maximeb_unity

    maximeb_unity

    Unity Technologies

    Joined:
    Mar 20, 2018
    Posts:
    121
    The idea is that the asmdefs in your own package can list defines that are enabled automatically when the specified package is present and it's version matches the version range you specify. This gives you control over the define name, and avoids clashes with the same names in other packages, all the while requiring no interaction on the part of the other package developer.
     
  5. jwvanderbeck

    jwvanderbeck

    Joined:
    Dec 4, 2014
    Posts:
    535
    That sounds about what we want. I'll play around with it once I get back from Siggraph. Thank you for the insight!
     
    maximeb_unity likes this.
  6. jwvanderbeck

    jwvanderbeck

    Joined:
    Dec 4, 2014
    Posts:
    535
    Ok so I'm back and taking a look at this now, but running into an immediate problem in that the Version Defines section isn't even showing up in my asmdef's inspector. I'm pretty sure I saw it there before so I'm not sure why it is gone now. Does it only show up under certain preconditions or only in certain Unity versions? I'm working in a couple different versions of the editor including 2018.3 and 2019.2.
     
  7. maximeb_unity

    maximeb_unity

    Unity Technologies

    Joined:
    Mar 20, 2018
    Posts:
    121
    As far as I know, this is a 2019.2+ feature. There's nothing specific that needs to be done to make it show up.