UE 热更
UE 热更
资源
使用插件HotPatcher,具体操作查看文档地址:https://imzlp.com/posts/17590/。
遇到一个问题:Io Store不能被打开:

所以在Project Settings -> Packaging -> Use Io Stroe 要取消,导出的pkg包就可以更新成功。
至于为什么没被打开,是因为CookPatchAssets打开时,Io Store是不被可用的。
代码
比较成熟的解决方案:
puerts
- 安装TS:
npm install -g typescript - 放到插件目录后查看
YouProject/Plugins/Puerts/Source/JsEnv/JsEnv.Build.cs设置的V8版本,再对应去下载 - 解压到
YouProject/Plugins/Puerts/ThirdPart,并在JsEnv.build.cs中修改UseV8Version设置为你所下载的版本。 - 在
YouProject/Plugins/Puerts目录下运行node ./enable_puerts_module.js - 在
YouProject目录下运行npm init -y - 在
YouProject/package.json中添加
"scripts": {
"build": "tsc -p tsconfig.json",
"watch": "tsc -p tsconfig.json --watch"
},
- 生成工程,启动引擎,点击运行游戏按钮旁边蓝色按键生成中间类。或者在引擎中运行
Puerts.Gen命令 - 在
YouProject目录下运行npm run build
UE.Load报错
报错:
Puerts: Error: (0x0000024DFC84E050) TypeError: Cannot read
properties of undefined (reading 'Load')
at F:\Learn\PuertsLearn\PuerTSDemo\Content\JavaScript\Blueprints\BP_Te
stActor.js:38:19
at executeModule (F:\Learn\PuertsLearn\PuerTSDemo\Content\JavaScript\p
uerts\modular.js:70:9)
at require (F:\Learn\PuertsLearn\PuerTSDemo\Content\JavaScript\puerts\
modular.js:183:29)
at F:\Learn\PuertsLearn\PuerTSDemo\Content\JavaScript\Main.js:3:1
at executeModule (F:\Learn\PuertsLearn\PuerTSDemo\Content\JavaScript\p
uerts\modular.js:70:9)
at require (F:\Learn\PuertsLearn\PuerTSDemo\Content\JavaScript\puerts\
modular.js:183:29)
根本原因:你使用的 TypeScript 6.0.2 默认强制启用 esModuleInterop,导致 import * as UE from 'ue' 被编译为 __importStar(require("ue"))
而不是直接 require("ue")。
__importStar 会把 PuerTS 的 UE 模块(一个依赖 Proxy 实现懒加载的对象)拷贝成一个普通对象,Proxy 的 get trap 不再生效。UE.Class
没有被预先注册(它需要在访问时通过 Proxy 触发 loadUEType("Class") 才能加载),所以返回 undefined。
修复:在 tsconfig.json 中添加了两个选项:
"esModuleInterop": false,
"ignoreDeprecations": "6.0"
这样 import * as UE 会直接编译为 const UE = require("ue"),保留 Proxy 懒加载机制。
注意 esModuleInterop: false 在 TS 7.0 将被移除,届时可能需要 PuerTS 官方适配(比如将 UE 模块的 __esModule 设为
true,或者换用其他模块加载方式)。
另一种方案是锁定TS的版本,在package.json中添加
"devDependencies": {
"typescript": "5.8"
}
然后 输入npm install 即可。
关于GC的问题
暂时不解决把