As a Unity developer, you may find yourself repeatedly importing the same packages for different projects. A custom package collection is a practical solution to streamline this process. By creating a package.json file tailored to your Unity version, you can save time and effort when importing packages.
In this tech guide, we’ll show you how to adjust the package.json file to your Unity version and discuss the benefits of using a custom package collection to speed up your workflow.
{
"name": "net.vrcreators.probuildercollection",
"displayName": "ProBuilder Collection",
"version": "1.0.0",
"unity": "2019.4",
"description": "A collection of packages for VR Creators, including ProBuilder, TextPro, PolyBrush, and ProGrids.",
"keywords": ["unity", "probuilder", "textpro", "polybrush", "progrids", "vrcreators"],
"author": {
"name": "VRCreators",
"url": "https://vrcreators.net"
},
"dependencies": {
"com.unity.probuilder": "~4.0",
"net.vrcreators.textpro": "~1.0",
"com.unity.polybrush": "~1.0",
"com.unity.progrids": "~3.0"
}
}
Create this as a packages.json file and keep it in a useful and familiar place to copy into your project folder OR fetch from.
Breaking down the Unity Packages.json #
Adjusting the package.json file for your Unity version #
Follow these steps to adjust the package.json file to match your Unity version:
- Locate the package.json file in your package folder. If you don’t have one, create a new file with the name “package.json”.
- Open the package.json file in a text editor.
- Identify the “unity” key in the JSON object. Its value represents the minimum supported Unity version for your package.
Example:
{
...
"unity": "2019.4",
...
}
- Modify the “unity” key value to match your Unity version. For example, if you’re using Unity 2020.3, change the value to “2020.3”.
- Update the version ranges for each dependency in the “dependencies” key, as needed.
Example:
{
...
"dependencies": {
"com.unity.probuilder": "~4.0",
"net.vrcreators.textpro": "~1.0",
"com.unity.polybrush": "~1.0",
"com.unity.progrids": "~3.0"
}
}
Check the documentation or Unity Package Manager for the correct package identifiers and version numbers that are compatible with your Unity version. Modify the version ranges as needed to ensure compatibility.
Why use custom package collections? #
Using a custom package collection offers several advantages for Unity developers:
- Faster Importation: By bundling frequently used packages into a single package.json file, you can quickly import them into your project. This approach saves time and speeds up the setup process for new projects.
- Consistency: Creating a custom package collection ensures that you’re using the same package versions across multiple projects, making it easier to maintain consistency.
- Easy Updates: When new package versions become available, updating your custom package collection is as simple as modifying the package.json file. This centralized approach makes it easy to keep your projects up to date with the latest package versions.
- Team Collaboration: If you’re working with a team, sharing a custom package collection ensures that everyone has access to the same packages and versions, reducing the likelihood of compatibility issues.
Using a custom package collection is a simple yet powerful way to speed up your Unity workflow. By adjusting the package.json file for your specific Unity version and bundling your favourite packages, you can save time, maintain consistency, and streamline your project setup process.