ποΈ Supported Unity Versions and Platforms
HybridCLR has stably supported the 2019.4.x, 2020.3.x, 2021.3.x, 2022.3.x LTS series and testing versions like 2023.2.x, 6000.x.y, and supports all platforms supported by il2cpp.
ποΈ Installation
Install Compatible Unity Version
ποΈ Configuration
After installing the com.code-philosophy.hybridclr package, you need to properly configure related parameters. For detailed configuration documentation, see hybridclr_unity Package Introduction.
ποΈ Assembly Configuration
Generally speaking, hot update code must be organized into independent assemblies to facilitate hot updates.
ποΈ Loading and Running
Loading Update Assemblies
ποΈ Build Workflow
Due to the requirements of hot updating itself and some limitations of Unity's resource management, special handling is needed for the build workflow, mainly divided into several parts:
ποΈ Publishing to WebGL Platform
Due to the many specificities of the WebGL platform, this document specifically describes how to publish to the WebGL platform. This document demonstrates the publishing process on the hybridclrtrial project (github gitee).
ποΈ Code Stripping
Unity uses code stripping technology to help reduce package size for the il2cpp backend. If anti-stripping measures are not taken, since there is generally not much code in the AOT main project, a large number of C# types and functions are stripped, causing hot update calls to these stripped classes or functions to result in the following exceptions:
ποΈ MonoBehaviour Support
HybridCLR fully supports hot update MonoBehaviour and ScriptableObject workflows, allowing you to add hot update scripts to GameObjects in code or directly attach hot update scripts to assets. However, due to the special nature of Unity's asset management mechanism, attaching hot update scripts to assets requires some special handling in the packaging workflow.
ποΈ PInvoke Support
Prior to version v8.0.0, defining extern functions in hot update code and attempting to call them would throw an ExecutionEngineException: method body is null error.
ποΈ MonoPInvokeCallback Support
When interacting with third-party languages like Lua, you need to call C# functions from these third-party languages. Two problems must be solved:
ποΈ AOT Generics
CLR has two types of generic features: generic types and generic functions. Generics are an extremely widely used feature in C#. Even code that doesn't obviously contain generic usage may implicitly include generic-related definitions or operations.
ποΈ Bridge Functions
HybridCLR's interpreter needs bidirectional function calls with AOT. For example, interpreter calling AOT functions, or AOT calling back to interpreter through interface or delegate callbacks.
ποΈ DOTS Support
DOTS's TypeManager initializes too early and doesn't support dynamic registration of Components and Systems. To make hot update modules run properly in DOTS systems, DOTS source code needs to be modified to adjust the initialization timing of World.
ποΈ Code Obfuscation
If hot update code is not obfuscated, tools like ILSpy can easily decompile it back to near-source-code C# code, posing serious threats to intellectual property and code security for commercial game projects and indie game development.
ποΈ Memory and GC
HybridCLR runtime memory consumption mainly consists of several parts:
ποΈ Execution Performance
Although HybridCLR also uses interpretation execution, both theoretical principles and real device testing data show that HybridCLR has dramatically improved performance (multiple times or even dozens of times) compared to popular hot update solutions like Lua and ILRuntime.
ποΈ Impact on App Package Size
The impact on package size after integrating HybridCLR mainly consists of the following parts:
ποΈ Impact on App Memory
After integrating HybridCLR, the impact on App runtime memory mainly consists of the following parts:
ποΈ Unsupported Features
HybridCLR supports all features not listed in the limitations below. Please don't ask whether HybridCLR supports a specific feature.
ποΈ hybridclr Package Manual
com.code-philosophy.hybridclr is a Unity package that provides Editor workflow tools and Runtime scripts required by HybridCLR. With the workflow tools provided by com.code-philosophy.hybridclr, packaging an App that supports HybridCLR hot update functionality becomes very simple. The hybridclr_unity package mainly contains the following content:
ποΈ Best Practices
Unity Version Recommendation
ποΈ Migrating from netstandard to .Net Framework
During Unity's packaging process, all references to netstandard.dll are converted to final references like mscorlib.dll, causing the original code's reference relationships to differ significantly from the final reference relationships. This difference causes the Generate/All/ commands to run with errors. Additionally, since the hot update dlls compiled by HybridCLR/CompileDll/ commands still reference netstandard rather than the final assemblies like mscorlib, loading and running hot update dlls will result in errors where types in netstandard cannot be found. Therefore, HybridCLR defaults to requiring the use of Net Framework Api Level.
ποΈ HybridCLR + lua/js/python
Some projects are already online with most of their code implemented in lua; or some new projects have been developed halfway using lua. They cannot completely switch to full C# development, but they want to integrate HybridCLR to help gradually transition to full native C# hot updates. Since HybridCLR is a native C# hot update technology, it natively supports working with these scripting languages.
ποΈ Code Structure and Versioning
The complete HybridCLR codebase consists of three repositories:
ποΈ HybridCLR Source Code Structure and Debugging
HybridCLR Module Introduction
ποΈ il2cpp Bug Record
Covariance and Contravariance Generic Interface Call Error