New in Unity 2017.3. Compiling scripts into separate build files

In previous versions of Unity, scripts were assembled into a single assembly Assembly-CSharp.dll.
And when adding new scripts, compilation time increased. Now in the new version it is now possible to define your own managed assemblies based on scripts inside the folder, which significantly reduces compilation time, especially in large projects. Now you can think of each managed assembly as a single library in a Unity project.


The figure above shows how you can split project scripts into multiple assemblies. If you only modify scripts in Main.dll, none of the other assemblies will need to be recompiled. Because Main.dll contains fewer scripts, it also compiles faster than Assembly-CSharp.dll.

Similarly, changes to the scripts you make in Stuff.dll will only recompile the Main.dll and Stuff.dll files.

How to use assembly definition files

Assembly definition files are asset files that you created by going to Assets → Create → Assembly Definition. This is a file with the extension .asmdef .

Note. The name of the folder in which the assembly definition file is located, and the file name of the assembly definition file do not affect the assembly name.



Create a Scripts folder. And her folders are Locomotion, Editor, Utils. In the Locomotion folder, there are two more folders, Normal and Anvanced. Now create the

Utils scripts → MoveExtension.cs

Locomotion → Anvanced → AdvJump.cs
Locomotion → Anvanced → AdvMoveForward.cs

Locomotion → Normal → Jump.cs MoveForward
Locomotion → Normal → MoveForward.cs

Locomotion → LookForward.cs

Editor → MoveForwardEditor.cs

And the MoveForwardEditor script let's define some code to need a link to MoveForward.

using UnityEditor;
public class MoveForwardEditor : Editor

Now, to create managed assemblies, we need to create .asmdef files in the script folder. Moreover, if this file is in a folder, say Locomotion, then it will pick up scripts from the Advanced and Normal folders in the assembly file if its assembly files are not defined in these folders.

In the Utils folder, create the assembly UtilityAsm.asmdef
In the Locomotion folder, create the assembly file LocomotionAsm.asmdef
In the Locomotion folder → Anvanced → LocomotionAdvancedAsm.asmdef
In the Editor folder EditorAsm.asmdef

In the Locomotion folder → Normal, we create nothing, because scripts from this folder will get into the LocomotionAsm assembly.

And here we get an error ...

Assets / Scripts / Editor / MoveForwardEditor.cs (3,22): error CS0246: The type or namespace name `MoveForward 'could not be found. Are you missing an assembly reference?


The MoveForwardEditor script swears that it cannot find a link to MoveForward. Everything is correct in this case MoveForward was in a different assembly and is not available. To fix this, you need to do the following

1. Select the EditorAsm assembly file
2. Click on +
3. Select the LocomotionAsm assembly file, because MoveForward is there.
4. From the platforms, leave only Editor
5. click Apply


Now the error is gone. And let's look in the Library folder and see our assemblies.


After assembling the project, we will also see these assemblies, except for EditorAsm, because This is an editor script.

There is another important point. Assembly files do not support preprocessor directives, as always static.

The article was written as an attempt to translate the official blog ) Thank you all for reading the article. Waiting for your comments.

Also popular now: