When you create a Unity Package Manager (UPM) package that contains code, you must include at least one assembly definition file (.asmdef
).
The Unity Editor relies on the assembly definition file to compile the scriptsA piece of code that allows you to create your own Components, trigger game events, modify Component properties over time and respond to user input in any way you like. More info
See in Glossary in your package as a separate unit. Unlike scripts in your project’s Assets
folder (which the Editor automatically compiles), the Editor ignores scripts inside the Packages
folder unless they’re part of an assembly definition.
For more information about assembly definitions, refer to organizing scripts into assemblies.
When you start developing your package, you need only one assembly definition per package folder that contains code (Editor
, Runtime
, Tests/Editor
, Tests/Runtime
). When you create a package using the Package Manager window, Unity creates the assembly definitions in these folders for you. If you decide to organize your code into more complex folder structures, you might need more assembly definition files:
.asmdef
files..asmdef
files for the code if you want to put that code in separate assemblies.If you create a more complex folder structure and need to create additional assembly definitions, refer to creating assembly assets.
Important: If the code in your Editor
folder depends on runtime code, then you need to add a reference from the Editor
assembly definition to the Runtime
assembly definition. For more information, refer to Adding a reference to another assembly. Runtime code cannot reference Editor code.
When you create a package using the Package Manager window, Unity populates some assembly definition fields for you. Use these steps to review the populated fields, add values to optional fields, and add references to other assemblies.
Note: Although you can edit .asmdef
files directly, the recommended best practice is to use the Unity Editor, which helps prevent errors and validates your changes.
To edit an assembly definition:
Open the Project window and go to the folder for your package.
Go to the Editor
, Runtime
, or Test
folder for the assembly definition you want to edit.
Select the assembly definition file.
Go to the InspectorA Unity window that displays information about the currently selected GameObject, asset or project settings, allowing you to inspect and edit the values. More info
See in Glossary window.
Set the fields as necessary. Common fields that might need editing include:
.asmdef
files.UnityEngine.UI
or an Editor
assembly that depends on a custom Runtime
assembly.Select Apply at the bottom of the Inspector window.