Use IL2CPP to precompile a game for Windows

Page update date :
Page creation date :

Verification environment

Windows
  • Windows 10
  • Windows 11
Unity Editor
  • 2020.3.25f1

About IL2CPP

If you build without IL2CPP, you will distribute the program in an intermediate language, compile it when the game is executed, and run the game. If you build using IL2CPP, you can compile it to native code at the time of build to improve performance when running the game and prevent disassembly.

For more information, please refer to the official Unity website.

The disadvantage is that the build time will be long, so please build by looking at the timing such as "preliminary survey", "final debug", "release". Or you may have a nightly build or something that you can keep up to date so that you can run it at any time.

Modular installation of IL2CPP (Windows)

IL2CPP requires additional modules.

Launch the Unity Hub and select Install from the menu on the left. Click the gear icon for the version you want to install IL2CPP on and select Add Module.

Check "Windows Build Support (IL2CPP)" in the platform group to install it.

Wait for the installation to complete.

Build and output with IL2CPP

Settings not listed here are the same as those of the game output for Windows, so please refer to them.

Open the project where you want to output the game.

Select File > Build Settings from the menu.

When the Build Settings dialog appears, click the "Player Settings" button at the bottom left. By the way, the dialog displayed by this button is the same as "Project Settings".

"Player" is selected in the menu on the left, so expand "Other Settings" from "PC, Mac & Linux Standalone Settings" at the bottom.

If you scroll down, you will find the "Scripting Backend" item in the "Settings" category, so select "IL2CPP".

After that, build as usual and output the game program.

It is slightly different from the file structure output when building with Mono.

IL2CPP produces more files and a larger total size, simply because it contains more files that are not needed for distribution.

You can run the game without the following:

Files & Foldersdescription
xxxx_BackUpThisFolder_ButDontShipItWithYourGame Note that this folder must not be distributed. Contains the code that is the basis for generating the program.
UnityCrashHandler64.exe This is the executable file of the crash handler. It is feasible even if you do not have it, but you can put it in.

If you remove the ones you don't need, IL2CPP will have a smaller file size.

It's a simple 2D game, so there's not much difference, but IL2CPP games consume less memory.

If the build fails

If you have installed Visual Studio 2019 that comes with Unity, there should be no problem. If you build without it, the following error message may be displayed. (Example)

Exception: C++ code builder is unable to build C++ code. In order to build C++ code for Windows Desktop, you must have one of these installed:
        Visual Studio 2015 with C++ compilers and Windows 10 SDK (it cannot build C++ code because it is not installed or missing C++ workload component)
        Visual Studio 2015 installation is found by looking at "SOFTWARE\Microsoft\VisualStudio\14.0_Config\InstallDir" in the registry
        Windows 10 SDK is found by looking at "SOFTWARE\Wow6432Node\Microsoft\Microsoft SDKs\Windows\v10.0\InstallationFolder" in the registry

        Visual Studio 2017 (or newer) with C++ compilers and Windows 10 SDK (it cannot build C++ code because it is not installed or missing C++ workload component)
        Visual Studio 2017 (or newer) installation is found using Microsoft.VisualStudio.Setup.Configuration COM APIs
        Windows 10 SDK is found by looking at "SOFTWARE\Wow6432Node\Microsoft\Microsoft SDKs\Windows\v10.0\InstallationFolder" in the registry

This is due to a missing component required to build with IL2CPP.

The following is a list of components that will be installed when you install Visual Studio 2019 with Unity. If the script editor is Visual Studio, install additional components from the list below. The higher the one, the more likely it is to need, and the one below is probably the one that you can put in or not.

  • C++ core features (perhaps required?) )
  • MSVC v142 - VS2019 C++ x64/x86 Build Tools (Latest) (required. Successor versions such as v143 and VS2022 are fine)
  • Windows 10 SDK (10.0.16299.0) (may be required.) Can the version be 16299 or later? )
  • MSBuild
  • C++ 2019 Redistributable Package Update
  • Visual Studio Tools for Unity
  • C# and Visual Basic Poslyn Compilers
  • .NET Framework 3.5 Development Tools
  • C# and Visual Basic
  • .NET Framework 4.7.1 Targeting Pack
  • NuGet Package Manager
  • Text Template Conversion

The following is the installation procedure.

Check and install what you need from here.