Building for AOT Platforms

AOT Pre-Build

Bolt supports all Unity build targets, including ahead-of-time (AOT) platforms like iOS, Android, WebGL, WSA and consoles. 

However, before building to AOT platforms, you need to run an additional step in order to trick the Unity compiler into forcing the compilation of reflected members and types ahead of time.

Fortunately, this is a one click operation. Simply open Tools > Ludiq > AOT Pre-Build and click Pre-Build :

If you forget to run this step, you may get errors that look like:

ExecutionEngineException: Attempting to call method (...) for which no ahead of time (AOT) code was generated. 

AOT Safe-Mode

Because AOT platforms do not safely support generics, generic types are by default not available in literals when you are targetting an AOT platform. To disable this behaviour, you can uncheck AOT Safe Mode in the Tools > Ludiq > Project Settings...

Scripting Backend

When building for Windows Store Apps (WSA / Metro), Bolt requires the use of the IL2CPP scripting backend. To change it, go to Edit > Project Settings > Player, choose the  panel and change the value of the following dropdown:

Cloud Build

The method Ludiq.AotPreBuilder.PreCloudBuild can be used to automatically hook into the cloud build process as a pre-export method name. See the Unity Documentation for more details.

This article was helpful for 11 people. Is this article helpful for you?

How does AOT pre-build work with Unity Cloud Build?


At the moment, there is no automation for cloud build. In v.1.2, I will add the following method which can be added as a pre-export method (documentation about this here):



Why doesn't AOT safely support generics? The platform supports generics fine in C# code -- is it because it's difficult to generate the bindings for generic code?


No, because the compilation is done ahead of time, types can't be left unresolved.   Imagine, if you will, if a generic appeared in a library: the AOT compiler has no idea what types will be fed into the generic, so it can't generate the types ahead of time (and thus, can't generate the method code for them). Thus, it can only support closed generics (those that the types can be resolved at runtime).

This is a limitation of the AOT compiler, not Bolt.  See here for more information:

Bolt's solution to this is to use the built-in AOTList, which is ArrayList (effectively, explicitly a List<object>, but supported by earlier .NET platforms) and a known compile target.