Search Unity

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:
    38
    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:
    756
    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:
    38
    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>?
     
  4. Thaina

    Thaina

    Joined:
    Jul 13, 2012
    Posts:
    1,163
    Some package from asset store could be required to install another package as dependency, in fact it could be game changer if asset in assetstore can refer to utility asset in github that was shared in many project instead of the need to pack all the duplicated library in one unitypackage file

    Sorry for digging this old thread but could you please consider making this feature officially secure in unity? Allow asset from assetstore to > ask for installation < of packages

    I mean, the `UnityEditor.PackageManager.Client` should be allowed for asset store to inject dependency. But then the unity editor would ask for permission with some popup to require user acceptance to avoid a package forcing inject another package into the scene. But then the asset package could be much more manageable