Unity Package Manager: How to Install a Specific Version of Package?
Often you need to install the specific version of a Package in Unity Package Manager (UPM) to match the requirements of a Tutorial or Asset on Unity Asset Store. There are 2 different ways to do it for Official Unity Packages and Git Packages. Let’s look at all the ways in more detail.
Contents
Official Unity Packages in Unity Package Manager
When you download an Asset from the Unity Asset Store (like AR Shooter from “Templates” category) that includes a Package Manifest, then Official Unity Packages (like AR Foundation) are installed with the target versions indicated in the manifest.
If you need a specific version of a target Unity Package that you can’t see in the UPM, you can set it manually in the next file: Folder of your Unity Project > Packages > manifest.json.
Git Packages in UPM
Git Package can’t be included in the Package Manifest of the Asset on the Unity Asset Store due to legal and security restrictions, so you need to install it manually before importing the asset itself to avoid compiler errors (tutorial example: Getting Started with AR Shooter Game Template).
When you Install a package from a Git URL, it is installed with the latest version by default, and not with the specific version.
Hash value = Specific Version of a Package
If you have any issues with the latest version, you can install the version indicated in the product that you are dealing with (Unity Tutorial or Unity Asset). To install the target version, you need to set manually the correct Hash value (commit indicator) which represents the target version of the package in the next file:
Folder of your Unity Project > Packages > packages-lock.json.
Hash value can be got from the commit link.
For example, let’s get the Hash value for the Native Camera 1.3.3:
- Open Git Repository of Native Camera.
- You can get hash value from different places: Releases, Tags, Commits.
- Find the Version 1.3.3 from Releases and the commit link with the title “72fca3d” near the date: github.com/yasirkula/UnityNativeCamera/commit/72fca3d1fc09efca842f1c1a50c13048bc8cd500 where 72fca3d1fc09efca842f1c1a50c13048bc8cd500 is a Hash value.
So the resulting object in packages-lock.json file will be like this:
"com.yasirkula.nativecamera": {
"version": "https://github.com/yasirkula/UnityNativeCamera.git",
"depth": 0,
"source": "git",
"dependencies": {},
"hash": "72fca3d1fc09efca842f1c1a50c13048bc8cd500"
}