Search Unity

Confusion About How to Create a Custom Package

Discussion in 'Package Manager' started by PartyBoat, Apr 16, 2019.

  1. PartyBoat

    PartyBoat

    Joined:
    Oct 21, 2012
    Posts:
    78
    So, I like to create a lot of modular assets that get reused across projects. It seems to me like the package manager would be a great way to manage adding these components without cluttering up my Assets folder. The support for Git also looks especially appealing.

    My problem is that the current documentation is fairly unclear/incorrect about how to create custom packages. Specifically the following doesn't make any sense:

    It's not possible to create a subfolder or even create anything at all in the Packages folder from within the Unity editor. Furthermore you can't move anything into the Packages folder. That being said, I suggest that the documentation should be edited to be more clear on this point.

    Does anybody have any idea how to create their own custom packages in 2019.1.02f? Bonus points if you know how to get things set up with git.
     
    Hypertectonic likes this.
  2. use_unity

    use_unity

    Unity Technologies

    Joined:
    Dec 26, 2017
    Posts:
    2
    Hi, PartyBoat. I wrote the documentation for Custom Packages, and I appreciate your feedback!

    You are correct: it is not possible to create a subfolder in the Packages directory from inside Unity. Although it is better to start inside Unity, I think most development will likely happen outside of Unity. For example, if you are creating a tool, you are mostly likely working in an IDE like Visual Studio.

    I will clarify the instructions for the next documentation updates. You do have to create the folder and the package.json manifest file inside the new folder through your computer's file system, as you noted. However, once you have done that and the Package Manager reads it, that folder is writable and you can create scripts, Materials, Playables, Textures, and tons of other Assets directly through the Inspector window.

    Please keep the feedback coming!
     
    Karlbovsky likes this.
  3. PartyBoat

    PartyBoat

    Joined:
    Oct 21, 2012
    Posts:
    78
    Ah I see, that makes a lot of sense. So if I understand correctly then, when developing a package it won't be installed as a package in the Unity project you are working on it in. Instead any other project can add it through the "Add package from disk..." option by navigating to that project and selecting the package.json in the file explorer.

    It might be worth noting in the docs that certain files like the package.json file will need to be created out of the editor (the current docs lead me to think the whole process could all be done in editor), although I suppose I should have known that considering txt files work the same way. :p

    Thanks for the help!
     
    use_unity likes this.
  4. samuelb_unity

    samuelb_unity

    Unity Technologies

    Joined:
    Nov 13, 2017
    Posts:
    40
    Just to clarify, there are 2 ways to create your own custom package:
    1. As an embedded package
    2. As a local package
    The difference is described on this page of the docs.

    So when you create a subfolder under Packages - that's called an "embedded" package. When you "Add package from disk..." that's called a "local" package. Either way, the package is installed in your project. The main difference is that a local package can be anywhere on disk whereas an embedded package is inside a specific project.
     
    Last edited: Apr 17, 2019
  5. Karlbovsky

    Karlbovsky

    Joined:
    Jul 11, 2012
    Posts:
    223
    Hi, I'll add my question here without opening a new thread since it's just about me being confused on how to proceed with the development of a package.
    I mean, given a project where I'm developing the package A, I will have all my scripts and assets inside the Project/Assets folder in order to add them to my GIT repository. If I create the package folder, put all the files needed in it, then i can not keep track of them in my "development" repo anymore, the only thing i can see in my remote repository, under the Package folder, is the manifest.json file. I know the question is not clear, but as I said, I'm a bit confused atm :p.
     
  6. samuelb_unity

    samuelb_unity

    Unity Technologies

    Joined:
    Nov 13, 2017
    Posts:
    40
    Hi @Karlbovsky,

    There are many possible workflows, it sounds like you just need to find one that fits your needs. If you want to develop a package in isolation, create a new project, create a package directory under Packages, and initialize a git repository there i.e. the root of the repository is your package folder.

    If you want to develop your package in the context of an existing project which itself is already a git repo, I think your best bet is to use a local package. Create a folder anywhere on your file system, initialize a git repository there, and refer to the package from a Unity project using the "Add package from disk..." button in the Package Manager window. This way your project and package repositories are completely separate.

    A more advanced workflow could be with git submodules. This basically lets you have nested git repos i.e. a repo at the root of your project, and a sub repo at the root of your package (under <my-project>/Packages).

    Let me know if you have any more questions!

    Regards,
    Sam
     
    Last edited: Apr 17, 2019
    Karlbovsky likes this.
  7. Karlbovsky

    Karlbovsky

    Joined:
    Jul 11, 2012
    Posts:
    223
    Hey, thanks! Really helpful advices.
    So, in the case of the second scenario, I can just create a folder ( not a Unity project) which contains the correct structure of a package with its relative files/assets/assemblyDef, refer to the new package from a Unity project by using the "Add package from disk" option and I'm good to go? Anyway, really in love with the Package Manager system already, is gonna be soooo useful!!

    Regards,
    Stefano.
     
  8. samuelb_unity

    samuelb_unity

    Unity Technologies

    Joined:
    Nov 13, 2017
    Posts:
    40
    Yep, that's right. And it's important to note: in this case the package folder doesn't get moved or copied when you add it to a project. We use symbolic links to reference it from the Unity project but it actually lives elsewhere. If you look in your project manifest after adding the package, you'll see how we refer to its location:

    Code (CSharp):
    1. "my-local-package": "file:/path/to/my-local-package"
     
    Karlbovsky likes this.
  9. davenirline

    davenirline

    Joined:
    Jul 7, 2010
    Posts:
    487
    Hello. We maintain our common code as a Unity project itself. It has the Assets, ProjectSettings, Package folders. I'm confused with the package layout. I assume we do that in Assets folder but the root of the repository has Assets, ProjectSettings, Package folders. Would it still work if we checkout the repository?

    What about cloud build? You mentioned there are many possible workflows but which workflow would work with cloud build?
     
  10. samuelb_unity

    samuelb_unity

    Unity Technologies

    Joined:
    Nov 13, 2017
    Posts:
    40
    Hi @davenirline, no the package layout refers to the root of the package directory. If the package lives inside a project, the structure would be:

    Project
    - Assets
    - ProjectSettings
    - Packages
    - MyPackage
    - package.json
    - README.md
    - etc.


    This should work fine with Cloud Build because the package directory is just like any other directory inside your project. Where it gets a bit more complicated is if the project is under source control and you want the package to be in its own source controlled repository. However, you might not need that. Let me know if you'd like more advice!
     
    davenirline likes this.