Best Practice for a package that relies on a git dependency?

I’m looking into creating a UPM package that contains some custom scripts that interface with a package available on a public git repository.

I can currently:

  1. Install the package from the public git repo.
  2. Install my custom package (with a dependency to package: x.x.x syntax).

Is there a way where I can skip the step to need to manually install the original dependency from git specifically? It looks like this is not supported or I misunderstand the documentation.

Is there a git based workflow where this could work? I guess I could fork that repo add my particular changes and then install just my particular package but that seems messy as well as I’ll always need to update via my upstream. Is there no way to resolve dependant packages that may not be installed as part of importing a package via UPM?

I’m using Unity 2021.3 LTS and currently just testing with “file from disk” if this makes any difference.

@scott_mk as far as I can tell that is NOT supported in 2021.3. According to the manual, git dependencies are only supported at the project level (not package).

Note: You cannot specify Git dependencies
in a package.json file because the Package Manager does not support Git dependencies between packages. It only supports Git dependencies for projects, so you can only declare Git dependencies in the project’s manifest.json file.”

There’s no ideal solution right now but here are two workarounds:

  • Put the public git dependency on OpenUPM (maybe it already is?). Then you can depend on it in your package and Unity will install and update it together with your package, since npm-based package dependencies are supported.
  • Use the git package as an optional asmdef dependency . Then you can conditionally compile the dependent code, so the project doesn’t break when the git package isn’t installed. Additionally, you could add some editor code to let the user know they can install the git package or even automatically do so.
2 Likes