Search code examples
c++unity-game-engineil2cpp

Is Unity3d native API via IL2CPP feasible?


I'm pondering an idea of accessing Unity3d's native API and possibly creating a wrapper library for easy human usage. To do that I'm currently trying to figure out what exactly happens when Unity project is converted to XCode project during build with IL2CPP flag on.

I'd like to know what is the exact process that goes on when IL2CPP translates IL to c++, why does the project still has DLL's included and is there anything special about the final compilation process e.g. where does the magic happen?

Any insights and opinions regarding the feasibility of described goal (Unity3d c++ API) are welcome.

PS: I understand that such an API would be hackish to say the least and yes, I do understand, that there are other technologies apart from Unity3d, that allow c++ usage as first-class citizen, namely Unreal Engine. This question is first and foremost theoretical in nature. That, and I also like c++ :)


Solution

  • No, nothing about the IL2CPP scripting backend exposes a new native API from Unity.

    There really isn't too much magic going on here, actually. The toolchain is something like this.

    1. Use the Mono compiler to generate IL assemblies from the C# code in the user's Unity project.
    2. Strip unused IL from the assemblies to convert to C++ (this help us decrease the fine code and binary size).
    3. Use IL2CPP to generate C++ code from the IL assemblies.
    4. Compile the C++ code with a C++ Compiler for the native platform (Xcode on iOS, Emscripten for WebGL)

    The only difference between using the Mono scripting backend and the IL2CPP scripting backend ouptut to Xcode for iOS is which files are included in the Xcode project. For IL2CPP, all of the generated C++ files are included.

    No matter which scripting backend you use those, the API for Unity is unchanged.