Search Unity

  1. Unity 2019.1 is now released.
    Dismiss Notice

Samples in Packages - Manual Setup

Discussion in 'Package Manager' started by ethan_jl_unity, Feb 1, 2019.

  1. ethan_jl_unity

    ethan_jl_unity

    Unity Technologies

    Joined:
    Sep 27, 2018
    Posts:
    11
    In Package Manager UI 2.0 (compatible with Unity 2019.1), you can include samples in a package.

    A sample could be a piece of example code, or some beginner assets that can be optionally brought into the user's project under the `Assets` folder.

    In the future, the editor will expose packaging functionality to properly expose samples, but in the meantime, here's is an example on how samples can be manually configured to be recognized in the Package Manager UI.

    First, make sure to place your samples under the `Samples~` folder.

    <Root>
    ├── package.json
    ├── Samples~
    │ ├── Sample Folder 1
    │ │ └── …
    │ └── Sample Folder 2
    │ └── …
    └── ...


    Then you need to specify them in the `package.json` file. Note that each sample needs to point to a directory.

    {
    "samples": [
    {
    "displayName": "Sample Name 1",
    "description": "Description for sample 1",
    "path": "Samples~/Sample Folder 1"
    },
    {
    "displayName": "Sample Name 2",
    "description": "Description for sample 2",
    "path": "Samples~/Sample Folder 2"
    }
    ]
    }


    Then you'll be able to see the import buttons in Package Manager UI as shown below.



    When the user chooses to import a sample, samples will be copied to the project’s `Assets/Samples/Package Name/Version/Sample Name` directory, thus allowing it to be modified.
     
    Last edited: Mar 4, 2019
  2. Novack

    Novack

    Joined:
    Oct 28, 2009
    Posts:
    596
    Thank you Ethan. As soon as I can move to Unity 2019.1 will jump into this.
     
  3. col000r

    col000r

    Joined:
    Mar 27, 2008
    Posts:
    644
    It took me a long time to figure out why this wasn't working for me. As it turns out, you need to spell samples with a lower-case s, so not upper-case like in your example ;)

    Code (CSharp):
    1.   "samples": [
     
    Novack and bddckr like this.
  4. ethan_jl_unity

    ethan_jl_unity

    Unity Technologies

    Joined:
    Sep 27, 2018
    Posts:
    11
    Oops sorry about that. :(

    @col000r Thanks for pointing it out! I just updated the post
     
  5. pablothedolphin

    pablothedolphin

    Joined:
    Oct 20, 2016
    Posts:
    54
    is this the only way assets like prefabs can be brought into projects from a package? or just the recommended way? what other options are there?
     
  6. okcompute_unity

    okcompute_unity

    Unity Technologies

    Joined:
    Jan 16, 2017
    Posts:
    443
    Hi @pablothedolphin

    (sorry for the delay)

    I don't understand your question. Can you elaborate more on your use cases?

    Regards,

    Pascal
     
  7. pablothedolphin

    pablothedolphin

    Joined:
    Oct 20, 2016
    Posts:
    54
    Sorry I should have elaborated more. I was hoping to design packages that would extend the create menu for the scene/hierarchy as cleanly as possible. For example, Unity offers menu options for creating UI objects that automatically add a canvas if there isn't one already, and the same for an event system. But the prefabs of those exact objects aren't in the assets folder because they shouldn't be. They're almost like "read only" prefabs that are just there to provide tools for developers.

    With my own package, I'd like to refer to prefabed objects that would be instantiated via editor scripts without needing to import those originals into the assets folder. Basically to have the same set up and Unity's own basic game objects.

    Is this something that can be done or will be considered for the package manager? I know I can just create plain game objects and add components to them but sometimes we need sprite references and other stuff that we don't necessarily want in the assets folder but in the packages folder.
     
  8. okcompute_unity

    okcompute_unity

    Unity Technologies

    Joined:
    Jan 16, 2017
    Posts:
    443
    @pablothedolphin No problems. I will transfer your question to the prefab team. Sadly, I don't know enough about the features/limitations of Prefab system to properly respond to your question.

    Let me reach out to them!
     
  9. okcompute_unity

    okcompute_unity

    Unity Technologies

    Joined:
    Jan 16, 2017
    Posts:
    443
    @pablothedolphin I just reach out the Prefab team. They told me there is no issue with using Prefab inside a package.