Search Unity

Feature Request URP/HDRP as optional dependencies?

Discussion in 'Package Manager' started by matias-lavik, Nov 23, 2022.

  1. matias-lavik

    matias-lavik

    Joined:
    Sep 9, 2019
    Posts:
    13
    Hi,

    I'm developing an open source volume rendering plugin where I'd like to support both legacy RP, URP and HDRP. There is one problem though: I don't want to require all my users to have the URP and HDRP package installed to use my plugin.

    AFAIK there are only two solutions to this:
    A: Add URP and HDRP as dependencies, and require all users to have both present.
    B. Do (A) for main repository, and set up a pipeline for automatically creating 3 unitypackages, for legacy RP, URP and HDRP.

    The problem with B is that it scales very poorly. If I also want to have two variants of my plugin with/without some other dependency (in my case SimpleITK), I would need to create 2x3=6 .unitypackages.
    It also doesn't allow people to add my plugin as a git submodule without having both packages installed.

    Is there a way to add "optional" dependencies? (or will you consider implementing that?)
    For example, it would be nice if I could:
    - Use #if UNITY_HDRP and #if UNITY_URP checks in C# code, to prevent compilation errors when URP/HDRP is missing.
    - Set up custom shader mappings for legacy->URP and legacy->HDRP, to select the correct shader for the selected RP.
    Or maybe even better:
    - Be able to select assets/scripts/folders that are ignored by Unity if some package (URP/HDRP) are not available.

    Is any of this possible today?

    Currently I'm thinking of solving this by writing some editor scripts that check if the packages are present, and then add UNITY_URP and UNITY_HDRP definitions to the selected build target, and also creating all material from code, but it feels a bit hacky.

    Thanks!
     
  2. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,282
    Yes, this is possible and something many of our existing packages already does.
    Assembly definition files let you create optional dependencies by using the Version Defines.https://docs.unity3d.com/Manual/ScriptCompilationAssemblyDefinitionFiles.html#define-symbols

    This will let you define UNITY_URP or UNITY_HDRP based on the presence of the package in the project.

    E.G
    upload_2022-11-23_10-21-21.png

    If you look at the HDRP package you can see it also has multiple optional dependencies
    upload_2022-11-23_10-24-38.png
     
    Last edited: Nov 23, 2022
    matias-lavik likes this.
  3. matias-lavik

    matias-lavik

    Joined:
    Sep 9, 2019
    Posts:
    13
    Thanks, this is exactly what I wanted! :)

    Is there also a similar way to deal with assets that depend on a plugin?
    If I create an asset that has a script from some package (universal render pipeline asset, etc.) then these will show up with "Missing script", and I suppose Materials using URP/HDRP shaders will have the same issue. Is there a similar way to exclude assets as well?