Loading lessons...
Custom Packages and Asset Workflow
Custom Packages and Asset Workflow
Unity's Package Manager allows you to create reusable toolkits distributed as packages. Custom packages can be shared via local paths, git repositories, or the Unity Asset Store.
Package Structure
A valid Unity package requires a specific folder layout:
com.yourname.mypackage/
package.json <- Required manifest file
Runtime/ <- C# scripts used at runtime
MyPackage.asmdef <- Assembly Definition
Editor/ <- Editor-only scripts
MyPackageEditor.asmdef
Tests/ <- Unit tests
Documentation~/ <- Markdown documentation (not imported)
README.md
CHANGELOG.md
LICENSE.md
The package.json Manifest
{
"name": "com.yourname.mypackage",
"version": "1.0.0",
"displayName": "My Awesome Package",
"description": "A reusable toolkit for Unity projects.",
"unity": "6000.0",
"unityRelease": "0f1",
"author": {
"name": "Your Name",
"email": "you@example.com"
},
"dependencies": {
"com.unity.inputsystem": "1.7.0"
}
}
Installing a Local Package
In the Package Manager, click the + button and choose:
- Add package from disk: Browse to the folder containing package.json.
- Add package from git URL: Enter a git repository URL.
// In your project's Packages/manifest.json
{
"dependencies": {
"com.yourname.mypackage": "file:../path/to/com.yourname.mypackage",
"com.yourname.gitpackage": "https://github.com/you/repo.git#v1.0.0"
}
}
Assembly Definitions for Packages
Each folder inside your package should have an Assembly Definition (.asmdef) file to:
- Create a separate compiled assembly (speeds up compilation).
- Define access control (which assemblies can reference yours).
- Separate Editor and Runtime code.
// Runtime/MyPackage.asmdef
{
"name": "YourName.MyPackage",
"rootNamespace": "YourName.MyPackage",
"references": [],
"includePlatforms": [],
"excludePlatforms": [],
"autoReferenced": true
}
AssetDatabase Scripting
When writing Editor tools, use AssetDatabase to manage assets programmatically:
using UnityEditor;
using UnityEngine;
public class AssetTool
{
[MenuItem("Tools/Create Default Material")]
static void CreateMaterial()
{
Material mat = new Material(Shader.Find("Universal Render Pipeline/Lit"));
AssetDatabase.CreateAsset(mat, "Assets/DefaultMaterial.mat");
AssetDatabase.SaveAssets();
AssetDatabase.Refresh();
EditorUtility.FocusProjectWindow();
Selection.activeObject = mat;
}
}
TL;DR
- Custom packages require a
package.jsonmanifest and a specific folder structure. - Name packages with reverse domain notation:
com.company.packagename. - Use Assembly Definitions to isolate Runtime vs Editor code and speed up compilation.
- Reference local packages via file paths or git URLs in the project's
manifest.json.