Lesson 59 +10 XP

Assembly Definitions

Assembly Definitions

By default, Unity compiles almost all of your C# scripts into a single giant DLL file called Assembly-CSharp.dll.

The Compilation Bottleneck

When you modify a single script, Unity has to recompile the entire project assembly. As your project grows, this can result in compile times of 10 to 30 seconds for every code change, slowing down development.

Assembly Definitions (.asmdef)

An Assembly Definition (.asmdef) asset allows you to divide your C# scripts into separate, independent assemblies.

  • When you modify a script in a specific assembly, Unity only recompiles that assembly and any other assemblies that depend on it.
  • This speeds up iteration times in the editor.

How to Create Assembly Definitions

  1. Create a folder for a module (e.g. "Plugins/AudioSystem").
  2. Right-click inside the folder and select Create -> Assembly Definition.
  3. Name it (e.g. AudioSystem).
  4. Any C# script in this folder (or subfolders) is now compiled into its own assembly.

Assembly References

If a script in Assembly-CSharp (your main scripts) wants to use a class in AudioSystem, it works automatically. However, if two separate assembly definition folders need to talk to each other:

  • Select the calling Assembly Definition asset in the Project window.
  • In the Inspector, add a reference to the target Assembly Definition under Assembly Definition References.
  • Click Apply.

TL;DR

  • Assembly Definitions compile scripts into modular, separate DLLs.
  • This speeds up compile times when modifying scripts.
  • Scripts inside one assembly cannot access classes in another unless a reference is defined.