Package Manger in C#
How to work with Unity's Package Manager in editor scripts
Last updated
How to work with Unity's Package Manager in editor scripts
Last updated
Support us as a and get instant access to all our assets, exclusive tools and assets, escalated support and issue tracking and our gratitude. These articles are made possible by our ... become a sponsor today!
Package Manager, while its not great it is what Unity Technology has moved to and it does give us what we need in terms of a means to query and see what is installed and detect the version that is installed.
These two namespaces give us everything we need to query what packages are installed and even kick off remove, update or installs operations.
The above code will use the PackageManager.Client to list all installed packages for you. Once the process is completed you should check for success and if so iterate over the results to find what your looking for.
The above example is a crude, non-practical example. Above we are simply searching for an installed package whose name matches System Core's package then setting a bool to true if its there and debug logging its version string.
In reality you would want to for example compare the version with a minimal require version, or perhaps you only care if its not installed so really a
would be more practice for you
The above example uses the PackageManager.Client to add Heathen's System Core tot he manifest. As with listing this is Asynchronous so you need to handle that for example:
This would simply yield until complete, this is an example only you could have timeout timers running or similar but it illustrates the point of waiting for that async process to complete.
Finally check for errors and handle them accordingly
The above code will print the error if any, if none it will print the version that was installed.
Installing or updating packages will cause the Unity editor to recompile and thus reload scripts, thus triggering any processes to fire again โฆ you need to uses parameters that can survive this to manage state.