Pre IL Code Generation
caution
this feature requires Unity 2019.3 or later.
VContainer has the ability to perform the meta programming part faster by generating IL code at compile time. As a result, there is no reflection at runtime, and it is expected to be 3-6x faster. It works in the IL2CPP environment.
With VContainer, for example, the following code (as IL) is automatically generated:
#
How to enable code generation modeVContainer.EnableCodeGen
asmdef to your references#
1. Add If you have asmdef in your project that refers to the following 2 asmdef, they are targets for IL weaving.
VContainer
VContainer.EnableCodeGen
#
2. Build your assemblyThe next time the specified assembly is compiled, VContainer will make changes to the compiled dll.
If it succeeds, it will be logged. For example:
VContainer code generation optimization for MyGame.dll 24 types (40.0355ms)
note
In Unity 2020.2 and later, the ILPostProcessor can no longer output logs. As a temporary measure, the above log is output as a warning, but it may be removed in the future.