Joris Eijmberts

Turning crazy ideas into games!

Assembly definitions

Assembly definitions in Unity at a high level are just groups of C# scripts that can be compiled separately. One of these ‘groups’ are usually referred to as a library or a DLL (dynamic link library) .

Source: Unity assembly definitions


When separating code into assemblies Unity is able to compile your edited code faster. This is achieved by only recompiling the assemblies that have been changed. Without using assemblies Unity has to recompile all scripts in the main assembly, for smaller projects this isn’t a big issue but when a project grows this will slow down editing scripts by a lot over time.

Furthermore when using assemblies you can manage your dependencies better seen as by default a new assembly doesn’t have any references to other code in the project except the code within the assembly.

CP Social assemblies

Platform dependent assemblies

When using assemblies in Unity it’s possible to enable platform dependent compilation per assembly. This makes sure that when Unity is building for a specific platform only the assemblies will be compiled into the final build when it’s allowed to be used on the target platform. The image below gives an example of what an assembly definition looks like in Unity.

For more info on Unity’s assembly definitions you can look at the documentation here.

CP Social android implementation assembly definition


A disadvantage to using assemblies in Unity is the dependency management, when you want to reference some code from a different assembly you have to add it to the dependencies of you current assembly. If you’re not used to this workflow it can be quite challenging to get right.


Using assembly definitions in CP Social saved a lot of work by creating a workflow that would automatically manage assemblies per target platform. Even though it didn’t solve all issues around platform dependent compilation it was a good start. To solve the rest of the platform dependent compilation I had to use pre-processor directives.