Assembly Definitions

 

[This topic is based on a quick research I made, and it's not intended to be used as reference.]


So, I've still got some catching up to do with my learning, and this time, I thought I'd tackle the Assembly Definitions topic. It's something I've been curious about because, yeah, it looks pretty tough (and it can be), but at its core, it's surprisingly straightforward.

Basically, we can use Assembly Definitions to speed up our changes. We know that testing something in Unity can be a pain because of the compilation time every time we make a code change. With this, our problems can be diminished.

When we create a project and start adding/creating our scripts, a single AD (short for Assembly Definition) is created. Every script we subsequently create is then attached to this single AD. However, as our project scales, it becomes slower because each change requires the recompilation of every script.

With Asembly Definitions, Unity can compile only what corresponds to the script you're editing. When you create a AD and associate it with a specific scripts folder, such as the "Enemy" folder, any changes made to scripts within that folder will prompt Unity to compile only those scripts. This can reduce the compilation time significantly.

So, it encorages you to make a more organized project, separating and organizing scripts that relate to each other.

I think thats basically it.

Of course, AD's offer additional functionalities. You can specify the platforms for which the scripts should be compiled, such as Android, or even limit it to the Unity Editor or specific Unity versions. That's being on the more advanced side of things, I won't wory too much about that for now.

When using an Assembly Definition (AD), it's essential to reference other ADs to access their code in your own. For instance, in programming, if you need to reference something like TextMeshPro (TMP), you typically use the TMP namespace. However, with ADs, you must first reference the TMP AD in your specific AD, let's say 'Enemy,' before you can use it in your code. So we need to be careful to not create some recursive references too, like referencing TMP on Enemy and Enemy on TMP.

Another cool feature is that we can see which script belongs to which AD on the inspector.

 




Comments