Search Unity

  1. Unity 2019.1 is now released.
    Dismiss Notice

Local Packages

Discussion in 'Package Manager' started by GodzillaSpider, Mar 1, 2019.

  1. GodzillaSpider

    GodzillaSpider

    Joined:
    Feb 21, 2018
    Posts:
    10
    I'm having problems using local packages with the Package Manager (2018.3.6f1). I have several questions:

    I want to use assets and scripts from project A in project B

    1) Where should package.json go in project A? It seems like any folder that I want files in and below that folder to be accessible to project B but just want to make sure.

    2) Should the scripts of the imported package be visible in the Visual Studio solution of project B? I do not see them in the VS solution but I do see them in project explorer under Packages in Unity.

    3) Should the scripts of the imported package be usable from scripts of project B? I seemingly cannot include the namespace of the imported scripts. Maybe this is because there is some compile error but how can I tell what the error is? The console gives no clues.

    4) If there is a StreamingAssets and/or Resources folder in the imported package, will that be treated the same way as those folders under Assets of project B?

    Thanks in advance.
     
  2. benoitv_unity

    benoitv_unity

    Unity Technologies

    Joined:
    Aug 3, 2017
    Posts:
    31
    Hi,

    We don't officially support custom package development at the moment so there is little documentation available. You can find some details about the structure of a package in the "Understanding how packages work" section of https://docs.unity3d.com/Packages/com.unity.package-manager-ui@2.1/manual/index.html. This older version of the same page (https://docs.unity3d.com/Packages/com.unity.package-manager-ui@1.8/manual/index.html) includes yet more details on the structure of packages in the "Advanced package topics" section

    For the scripting side of it, Package code requires Assembly Definition files to. Those are akin to .csproj files in traditional C# solutions. In your case, asmdef files of package B would need to reference asmdef files of package A. You can find more info on the subject here https://docs.unity3d.com/Manual/ScriptCompilationAssemblyDefinitionFiles.html

    As for resources folder, they are indeed treated like the ones under "Assets".

    Regards,
    Benoit
     
  3. GodzillaSpider

    GodzillaSpider

    Joined:
    Feb 21, 2018
    Posts:
    10
    Benoit,

    Thanks for the help. I was able to get it working after arranging the asmdef files properly.

    Any hint as to when the support of custom package development will be "official"?

    Thanks

    Leo
     
    phobos2077 and markgrossnickle like this.
  4. benoitv_unity

    benoitv_unity

    Unity Technologies

    Joined:
    Aug 3, 2017
    Posts:
    31
    Hi Leo,

    A new Package Manager user manual will be available as of 2019.1. It should contain enough information for users to start toying with custom packages. However, most of the configuration will still need to be done manually. Proper UX for creating and publishing packages will come in a later release, but I don't have an ETA at the moment.

    Regards,
    Benoit
     
  5. GodzillaSpider

    GodzillaSpider

    Joined:
    Feb 21, 2018
    Posts:
    10
    Benoit,

    A couple more issues that maybe you can shed some light on...

    1) In debug mode, I cannot "step into" the scripts from the imported package. However, I can go to the definition of the imported function I'm using and set a breakpoint and that does work. So there is a reasonable workaround but "stepping into" doesn't seem to work properly.

    2) How do I access StreamingAssets files from the imported package? Application.streamingAssets still points to the StreamingAssets folder of the local project. Is there a different method to get a list of folders or to combine all StreamingAssets into the local folder?

    Thanks

    Leo
     
  6. benoitv_unity

    benoitv_unity

    Unity Technologies

    Joined:
    Aug 3, 2017
    Posts:
    31
    Hi,

    1) I get the same behavior on my end, I will file a bug.

    2) There is an effort with packages to get away from so-called "magic" folders. To access any package asset, all you need is to provide the path "Packages/my-package-name/path/to/asset" . Package paths are always remapped this way in the asset database regardless of where the package is located on disk. So even if you upgrade the version of the package, the package assets will remain accessible in the same way.

    Regards,
    Benoit
     
    phobos2077 likes this.
  7. 479813005

    479813005

    Joined:
    Mar 18, 2015
    Posts:
    37
    By the way, when will Asset Store support custom package?
     
    phobos2077 likes this.
  8. N3uRo

    N3uRo

    Joined:
    Dec 10, 2011
    Posts:
    597
    We have our own code base in our organization and we have separate it in *.asmdef files. We now want to create custom packages and I see that we can reference them manually from a path as I see in that documentation.

    My problem is that I want a system that it's more maintanable and scalable.

    I would want to have them versioned and also have a way to publish a "newer" version and be able to see it from the package manager UI (custom repositories I should say). Is it possible now or is it to soon to ask this?

    I want to see if I should wait into converting them to packages until you have that features available.
     
  9. benoitv_unity

    benoitv_unity

    Unity Technologies

    Joined:
    Aug 3, 2017
    Posts:
    31
  10. benoitv_unity

    benoitv_unity

    Unity Technologies

    Joined:
    Aug 3, 2017
    Posts:
    31
    Hi @479813005,

    We have started work to support packages on the Asset store but I can't give you an ETA at the moment.

    Regards,
    Benoit
     
    phobos2077 likes this.
  11. benoitv_unity

    benoitv_unity

    Unity Technologies

    Joined:
    Aug 3, 2017
    Posts:
    31
    phobos2077 likes this.
  12. GodzillaSpider

    GodzillaSpider

    Joined:
    Feb 21, 2018
    Posts:
    10
    Benoit,

    Thanks for the followup!

    I have a couple more issues in working with the package manager so far:

    1) I subdivided the common code I wanted to share among projects into modules and put an asmdef in each module. When I load a package with dependencies through the package manager, I immediately get a complaint that the asmdef in the imported package references an unknown asmdef (from one of the dependencies). I was able to get around this by loading the dependencies first but I was hoping the package manager would automatically load package dependencies and only try to resolve asmdef references after loading all dependencies. Not sure if it's a bug or feature request.

    2) I am able to reference files in imported packages as you suggested when running through the editor. However, I have yet to figure out how to access those files on Android. Previously, Application.streamingAssetsPath + WWW was required because StreamingAssets was compressed on Android. How do files in imported packages work for this case?

    Thanks for your help

    Leo
     
  13. M_R

    M_R

    Joined:
    Apr 15, 2015
    Posts:
    394
    1) your package manifest should declare its dependencies to other packages (only version is supported there, but at least you get a 'cannot find package' instead of 'cannot find asmdef' that may not have the same name -- and it fails earlier. or you set up a scoped registry and the version is resolved from that)

    2) direct references still work. Resources can have direct references to stuff outside Resources and those can be in packages. StreamingAssets you must copy them to Assets/StreamingAssets (you can do it as a build step with
    IPreprocessBuild.OnPreprocessBuild
    )
     
  14. GodzillaSpider

    GodzillaSpider

    Joined:
    Feb 21, 2018
    Posts:
    10
    1) So let me confirm my understanding - The following dependencies in a package.json are not yet supported as they specify a local package dependency instead of a version number::

    Code (CSharp):
    1. "dependencies": {
    2.         "com.test_co.holotoolkit": "file:../../Common/Redist/HoloToolkit",
    3.         "com.test_co.vuforia": "file:../../Common/Redist/Vuforia",
    4.         "com.test_co.filehelper": "file:../FileHelper"
    5.     }
    Or am I using an incorrect syntax?

    2) Got it thanks!
     
    Last edited: Mar 11, 2019
  15. M_R

    M_R

    Joined:
    Apr 15, 2015
    Posts:
    394
    1) yes. you can declare local/git dependencies in your project manifest like that but not in a package.json.
    you can declare
    Code (CSharp):
    1. "dependencies": {
    2.         "com.test_co.holotoolkit": "1.2.3",
    3.         "com.test_co.vuforia": "2.3.4",
    4.         "com.test_co.filehelper": "3.4.5"
    5.     }
    and the error will be "cannot resolve com.test_co.holotoolkit" etc... so you know you need to add that package from wherever it is (put a note in the README for it) into your project

    or you setup a scoped registry like this:
    Code (CSharp):
    1. "scopedRegistries":[
    2.     {
    3.         "name": "Your Registry",
    4.         "url": "url",
    5.         "scope":"com.test_co"
    6.     }
    7. ]
    and upm will know to search for packages that begin with "com.test_co" in your registry instead of Unity's. (see the sticky thread in this forum for details)
     
    phobos2077 likes this.
  16. GodzillaSpider

    GodzillaSpider

    Joined:
    Feb 21, 2018
    Posts:
    10
    Understood, thanks for your help. I hope the local dependency resolution will be added at some point. We are using ClearCase version control (I know it's ancient) and that's the best way for us to share code.