Unity provides two special asset types, Assembly Definitions and Assembly References, to help organize your 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 into assemblies.
An assembly is a C# code library that contains the compiled classes and structs that are defined by your scripts and which also define references to other assemblies. Refer to Assemblies in .NET for more information about assemblies in C#.
By default, Unity compiles almost all of your game scripts into a predefined assembly called Assembly-CSharp.dll
. Unity also creates a few smaller, specialized predefined assemblies.
This arrangement works acceptably for small projects, but has some drawbacks as you add more code to your project:
By defining assemblies, you can organize your code to promote modularity and reusability. Scripts in assemblies you define are no longer added to the default assemblies and can only access scripts in your other custom assemblies.
The above diagram illustrates how you might split up the code in your project into multiple assemblies. Because Main references Stuff and not the other way around, you know that any changes to the code in Main cannot affect the code in Stuff. Similarly, because Library doesn’t depend on any other assemblies, you can more easily reuse the code in Library in another project.
To organize your project code into assemblies, create a folder for each desired assembly and move the scripts that should belong to each assembly into the relevant folder. Then create Assembly Definition assets to specify the assembly properties.
Unity compiles all the scripts in a folder that contains an Assembly Definition into a single assembly, using the name and other settings defined by the asset. The assembly includes any scripts in subfolders unless a subfolder has its own Assembly Definition or Assembly Reference asset.
To include scripts from a non-child folder in an existing assembly, create an Assembly Reference asset in the non-child folder and set it to reference the Assembly Definition asset that defines the target assembly. For example, you can combine the scripts from all the Editor folders in your project in their own assembly, no matter where those folders are located.
Unity compiles assemblies in an order determined by their dependencies. You can’t specify the order in which compilation takes place.
To identify which assembly a script belongs to, select the script file in the Project window to view its properties in 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. The assembly filename and the Assembly Definition, if one exists, are shown in the Assembly Information section of the Inspector.
Unity normally compiles any scripts in folders named Editor
into the predefined Assembly-CSharp-Editor
assembly no matter where those scripts are located. However, if you create an Assembly Definition asset in a folder that has an Editor folder underneath it, Unity no longer puts those Editor scripts into the predefined Editor assembly. Instead, they go into the new assembly created by your Assembly Definition — where they might not belong. To manage Editor
folders, you can create Assembly Definition or Reference assets in each Editor
folder to place those scripts in one or more Editor assemblies. For more information, refer to Creating an assembly for Editor code.
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thank you for helping to make the Unity documentation better!
Your feedback has been submitted as a ticket for our documentation team to review.
We are not able to reply to every ticket submitted.