Search Unity

  1. Calling all beginners! Join the FPS Beginners Mods Challenge until December 13.
    Dismiss Notice
  2. It's Cyber Week at the Asset Store!
    Dismiss Notice

Is there a scripting API to view installed projects?

Discussion in 'Package Manager' started by ChrisDirkis, Jun 20, 2018.

  1. ChrisDirkis

    ChrisDirkis

    Joined:
    Jun 1, 2017
    Posts:
    37
    As per the title. The specific usecase is "in [initializeonload], if the post processing package isn't installed, install it with UnityEditor.PackageManager.Client.Add("com.unity.post-processing")".

    I can't find anything relevant under the namespace, nor in the c# source. Either a way to do this, or a better way to add the package, would be appreciated.

    Worst case, I can examine the project's package manifest manually, edit the json, and force the project to reload, I guess?
     
  2. okcompute_unity

    okcompute_unity

    Unity Technologies

    Joined:
    Jan 16, 2017
    Posts:
    609
    Hi @ChrisDirkis ,

    There is a method to fetch the list of packages added to the project: https://docs.unity3d.com/ScriptReference/PackageManager.Client.html
    See the
    List()
    method documentation.

    The method will return a collection of
    PackageInfo
    (https://docs.unity3d.com/ScriptReference/PackageManager.PackageInfo.html)

    This is asynchronous though (same for
    Add()
    method btw). Make sure you want to fire an async method on
    InitializeOnLoad
    . You will have to track the request completion in future *update* callbacks.

    If you know the exact version of the package, you could also always add the package. If the package is already in the project manifest, it will be a noop.

    Example:
    UnityEditor.PackageManager.Client.Add("com.unity.post-processing@2.0.7-preview")".


    I'm curious though. Could you describe your use case a bit more Why do you want to do this? The PackageManager API was built to create package manager user interfaces. Forcing a package in a project seems dangerous!

    Regards,

    Pascal
     
  3. ChrisDirkis

    ChrisDirkis

    Joined:
    Jun 1, 2017
    Posts:
    37
    The usecase is purely internal -- we have our own package manager at my org, and we're wanting to add dependencies from these packages to UPM packages. Ideally, we'd just distribute our packages through UPM and do the dependencies manually, but we'd rather wait for proper personal repo support from Unity to show up instead of trying to add our own package source references for now :)

    As such, just adding the package with specified version will work well for us (single import at the start of the project as a framework, no updating). Definitely agree that doing this in a published Asset would be bad juju.

    Out of curiosity: Any reason the Request classes are being used over Task<T> or some generic Request<T>?