How to create a Custom Package in Unity

Lalo Berro
2 min readMay 6, 2022

--

Introduction

Unity give us the chance to create own custom package for the Package manager. This allow us to create modules to share between projects.

If we press the plus button on the package manager we are going to see four ways to import a custom package into our project:

  • From Disk: in this option you have to select the folder of the package in your computer.
  • From Tarball: https://docs.unity3d.com/Manual/upm-ui-tarball.html.
  • From Git URL: in this option you have to paste the git url of the package, this is the best option and we are working with this.
  • By Name: in this option you have to put the package id like com.unity.example, note that package has to be in unity registry.

Package Layout

<root>
├── package.json
├── README.md
├── LICENSE.md
├── Editor
│ ├── [company-name].[package-name].Editor.asmdef
│ └── EditorExample.cs
├── Runtime
│ ├── [company-name].[package-name].asmdef
│ └── RuntimeExample.cs
├── Tests
│ ├── Editor
│ │ ├── [company-name].[package-name].Editor.Tests.asmdef
│ │ └── EditorExampleTest.cs
│ └── Runtime
│ ├── [company-name].[package-name].Tests.asmdef
│ └── RuntimeExampleTest.cs
├── Samples~
├── SampleFolder1
├── SampleFolder2
└── ...

Create Git Repository

  1. Follow this repository for add it to templates:

https://github.com/LaloBerro/UnityPackageTemplate

  1. Create a New Repository
  2. Select the UnityPackageTemplate as template of the repository
  3. Put a name like UnityPackage-NameExample
  4. Create Repository.
  5. Add the package to unity from Git Url.

Add the content to the package

  • Runtime Folder: in this folder add all the scripts that don’t have an editor reference.
  • Editor Folder: in this folder add all the scripts that have an editor reference.
  • If you package have test add it on the Test folder.

Create a Samples folder

  1. Add this line to package.json
  • "samples": [ { "displayName": "<displayname>", "description": "", "path": "Samples~/<foldername>" }
  1. Add the folder Samples~ to the root of the package.
  2. When the Samples folder in assets is ready to the package:
  3. Export the folder as a unity package.
  4. Save the package on the assets root folder.
  5. Put it on a folder named equal that the in package.json <foldername> .
  6. Put this entire folder with his .meta on /Samples~.
  7. On .gitIgnore delete the ignore of .unitypackages.
  8. If you want to update the samples, only you have to replace the .unitypackage in the folder /Samples~/<foldername>/.

--

--

Lalo Berro

Im Lalo a passionate videogame programmer that loves share quality and advanced content.