From 61c2aa30c58e233caba318ee72ca4599be7ef95b Mon Sep 17 00:00:00 2001 From: walon Date: Thu, 29 Aug 2024 18:49:13 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E6=96=87=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/beginner/monobehaviour.md | 8 ++++++++ .../current/beginner/monobehaviour.md | 6 ++++++ 2 files changed, 14 insertions(+) diff --git a/docs/beginner/monobehaviour.md b/docs/beginner/monobehaviour.md index a3332bc86..e29fb9b54 100644 --- a/docs/beginner/monobehaviour.md +++ b/docs/beginner/monobehaviour.md @@ -23,6 +23,13 @@ public class Print : MonoBehaviour } ``` +## 解决GameObject被裁剪的问题 + +由于快速上手中完全没有用到GameObject,导致GameObject类型的部分函数在打包时被裁剪。`HybridCLR/Generate/All`命令会重新扫描热更新程序集,生成link.xml以保留热更新代码中用到的类型。 + +请运行完该命令后**重新构建一次新包**,否则运行下一步的热更新代码时会出现`GameObject::.ctor`函数找不到的错误。 + + ## 代码中调用AddComponent来动态挂载热更新脚本 修改 `Hello.Run`函数,添加动态挂载Print脚本的代码,最终代码如下: @@ -51,3 +58,4 @@ public class Print : MonoBehaviour 对于新手来说,你只需要记住:挂载热更新脚本的资源(场景或prefab)必须打包成ab,在实例化资源前先加载热更新dll即可(这个要求是显然的!)。 + diff --git a/i18n/en/docusaurus-plugin-content-docs/current/beginner/monobehaviour.md b/i18n/en/docusaurus-plugin-content-docs/current/beginner/monobehaviour.md index b62e33c85..f80abe7a6 100644 --- a/i18n/en/docusaurus-plugin-content-docs/current/beginner/monobehaviour.md +++ b/i18n/en/docusaurus-plugin-content-docs/current/beginner/monobehaviour.md @@ -24,6 +24,12 @@ public class Print : MonoBehaviour } ``` +## Solve issue of GameObject being stripped + +Since GameObject is not used at all in the quick start, some functions of the GameObject type are stripped when building. The `HybridCLR/Generate/All` command will rescan the hot update assembly and generate link.xml to retain the types used in the hot update code. + +Please **rebuild a new package** after running this command, otherwise the error `GameObject::.ctor` function cannot be found will appear when running the next hot update code. + ## Call AddComponent in the code to dynamically mount the hot update script Modify the `Hello.Run` function and add the code to dynamically mount the Print script. The final code is as follows: