Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Unity Scripting Backend - C++breaktime 2026 Summer

Unity Scripting Backend - C++breaktime 2026 Summer

2026/6/19 C++ breaktime 2026/Summer
「Unity Scripting Backend」遥佐保

Avatar for Akiko Kawai

Akiko Kawai

June 20, 2026

More Decks by Akiko Kawai

Other Decks in Programming

Transcript

  1. Scripting Backend https://docs.unity3d.com/ja/current/Manual/scripting-backends.html Unity Game Engine (C++) C# Mono IL2CPP

    CoreCLR Original Game Engine (C++) C++ Original Game Engine (C++) Original Script To Native
  2. Unity Game Engine (C++) C# IL C++ Compile Convert (IL2CPP)

    Unity Game Engine (C++) C# IL JIT Compiler Compile ビルド時 ゲーム実行時 Mono : JITコンパイル方式 IL2CPP : AOTコンパイル方式 ビルドが遅い 実行時は速い ビルドが速い 実行時にちょっと負荷あり
  3. https://github.com/Unity-Technologies/UnityCsReference // UnityCsReference/Runtime/Transform/ScriptBindings/Transform.bindings.cs using UnityEngine.Bindings; using UnityEngine.Scripting; namespace UnityEngine {

    // Position, rotation and scale of an object. [NativeHeader("Configuration/UnityConfigure.h")] [NativeHeader("Runtime/Transform/Transform.h")] [NativeHeader("Runtime/Transform/ScriptBindings/TransformScriptBindings.h")] [RequiredByNativeCode] public partial class Transform : Component, IEnumerable { // The position of the transform in world space. public extern Vector3 position { get; set; } ...
  4. Unity Game Engine (C++) C# IL JIT Compiler Compile ビルド時

    ゲーム実行時 Mono : JITコンパイル方式 CPU出るたびに対応。。。これは地獄じゃろ
  5. Unity Game Engine (C++) C# IL JIT Compiler Compile ビルド時

    ゲーム実行時 Mono : JITコンパイル方式 CPU出るたびに対応。。。これは地獄じゃろ もしかして… これをC++にすればいいのでは… Unity Game Engine (C++) C# IL C++ Compile Convert (IL2CPP) ネイティブ対応はClangとかVCとか、 ブラウザならEmscriptenがやってくれるやん! IL2CPP 移植性の高いC++無双基盤
  6. Unity Engine Process (C++) Mono, IL2CPP, CoreCLR User C# source(*.cs)

    MonoBehaviour, ScriptableObject … Host Guest C# IL C++ Compile Convert (IL2CPP) AOT Compile Runtime C++とC#の やり取りは自作
  7. Nativeの世界 il2cpp.exe が作る IL→C++ のコードの解説 IL2CPP internals: A tour of

    generated code https://unity.com/blog/engine-platform/il2cpp-internals-a-tour-of-generated-code C#で書かれた class や struct と全く同じメモリレイアウトを持つ C++の struct を自動生成するやり方 // C# public struct Vector3 { public float x; public float y; public float z; } // C++ struct Vector3_t78 { float ___x_1; float ___y_2; float ___z_3; } IL2CPP internals: P/Invoke Wrappers https://unity.com/blog/engine-platform/il2cpp-internals-pinvoke-wrappers Blittable型(C#とC++でメモリ表現 が同じ型)の配列をC++プラグイン に渡す場合は メモリのコピーはせず、ポインタを 渡すだけ Unity Game Engine (C++) C# C++
  8. C# source (*.cs) IL Assembly (*.dll) Roslyn Compiler C++ source

    (*.cpp) IL2CPP Compiler https://docs.unity3d.com/6000.4/Documentation/Manual/il2cpp-introduction.html Nativeへ FYI:その後UnityはBurst Compilerを開発しました (IL2CPPの置き換えにはならない) C# source (*.cs) Burst Compiler C++ Compiler Roslyn Compiler IL Assembly (*.dll) Nativeへ LLVM