Home > Mobile >  Which assemblies will be recompiled if one script changed in Unity?
Which assemblies will be recompiled if one script changed in Unity?

Time:01-30

In Unity, assembly can be used to accelerate compiling.
I used to believe that if one script changed, only its containing assembly is recompiled.

I did some experiments today, and find that not only the containing assembly is recompiled.
For example, Assembly-CSharp.dll is recompiled most of the time.

Assume script 'a' belongs to assembly 'A'.
Based on my experiments, adding/deleting public field or method, assemblies that reference 'A' will be recompiled. Modifying content of a public method will not cause referencing assemblies to be recompiled. adding/deleting/modifying private things will not cause referencing assemblies to be recompiled either.

So, which assemblies will be recompiled if I change one script in Unity?
Is there any article or book about this?

CodePudding user response:

It's all about dependencies. Unity makes use of c# which uses CSharpCompiler (here), you can look up MSDN directly to get in depth understanding on the build/compilation process.

There are lots on intricacies but I will try to explain the basic cases consider you have 2 assemblies A and B

  • 'A' and 'B' are independent in this case changing any code in 'A' will only build 'A' and changing 'B' will only build 'B'
  • 'A' is dependent on 'B', in this case changing 'A' will build only 'A' but changing 'B' will build 'B' followed by 'A'
  • 'A' is dependent on 'B', but you have excluded 'B' from build process using Visual Studio Configuration Manager , in this case no matter which assemblies you change 'B' will never be built and will continue to have outdated code

So this problem can get complicated very soon say if you have 5 assemblies, if compilation time is really important for you, it's a good idea to think about structuring the code which is a big topic altogether

  • Related