zworld-em/Plugins/UnLua/Source/UnLuaDefaultParamCollectorUbtPlugin/README.md
2025-05-11 22:07:21 +08:00

44 lines
3.1 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# UnLuaDefaultParamCollectorUbtPlugin
## 概述
这是 UnLua 插件中 UnLuaDefaultParamCollector 模块的 C\# 版本,用于让引擎启用 C\# 版本的 UHT (UnrealHeaderTool) ,从而解决在 UE5\.1 中编译 UnLua 插件时出现以下编译警告的问题。
```
DEPRECATED: C++ UHT being used because 'UnLua' does not have a C# version. C++ UHT has been deprecated and will be removed in 5.2
```
## 原理
在 5\.1 或更高版本的引擎中UnLuaDefaultParamCollectorUbtPlugin 会取代 UnLuaDefaultParamCollector在编译 UHT 时导出 DefaultParamCollection\.inl具体实现请见 UnLuaDefaultParamCollectorUbtPlugin\.cs。UnLuaDefaultParamCollectorUbtPlugin 和 UnLuaDefaultParamCollector 导出的 DefaultParamCollection\.inl 是大致相同的,区别有以下几点:
+ 前者在文件头处增加了一行注释 `// Generated By C# UbtPlugin`;在测试的时候,可以检查导出文件的开头是否包含该行注释,以此判断引擎是否启用了 C\# 版本的 UHT
+ 前者导出的注释,增加了 `ModuleType` 枚举值名称的输出;当前的注释形如 `// ModuleName CoreUObject Type EngineRuntime(1) ModuleGeneratedIncludeDirectory C:/UE5.1/Engine/Intermediate/Build/Win64/UnrealEditor/Inc/CoreUObject/UHT`,而此前的注释形如 `// ModuleName CoreUObject Type 1 ModuleGeneratedIncludeDirectory C:/UE5.1/Engine/Intermediate/Build/Win64/UnrealEditor/Inc/CoreUObject/UHT`
+ 部分类型的导出顺序有所变化;原因是 C\# 和 C\+\+ 遍历引擎类型的顺序有所不同,不过除了顺序之外,导出的类型和函数都是相同的
原来的 UnLuaDefaultParamCollector 并不需要删除,它会在 5\.0 或更低版本的引擎中生效。低版本的引擎仍然会使用 C\+\+ 版本的 UHTUnLuaDefaultParamCollectorUbtPlugin 的存在对此没有任何影响。
## 测试记录
+ 在 develop 分支 [4601f2f-2023/3/7](https://github.com/Tencent/UnLua/commit/4601f2f7b9a1cf96448d7582b7283addc7898730) 版本下测试正常
+ 在 [UnLua 2.3.3](https://github.com/Tencent/UnLua/releases/tag/v2.3.3) 版本下测试正常
+ 在 [UnLua 2.4.0](https://github.com/Tencent/UnLua/releases/tag/v2.4.0) 版本下测试正常
## 注意事项
UnLuaTestSuite 也是一个可以被引擎 UHT 调用的插件(在 UnLuaTestSuite\.uplugin 中,`CanBeUsedWithUnrealHeaderTool` 是 true而且也没有提供 C\# 版本的模块。因此如果一个项目,例如 TPSProject还包含 UnLuaTestSuite 插件的话,在编译时就会出现另一个警告。
```
DEPRECATED: C++ UHT being used because 'UnLuaTestSuite' does not have a C# version. C++ UHT has been deprecated and will be removed in 5.2
```
请注意UnLuaDefaultParamCollectorUbtPlugin 只能去除 UnLua 插件的警告,并不能去除以上由 UnLuaTestSuite 插件引起的警告。换言之,**如果一个项目包含了 UnLuaTestSuite 插件,在编译时引擎就仍然会调用 C\+\+ 版本的 UHT**。按照官方的说法,在正式项目中并不需要用到 UnLuaTestSuite 插件,因此如果发现 UnLuaDefaultParamCollectorUbtPlugin 没有生效,或者 UHT 警告仍然存在,请检查项目是否多包含了 UnLuaTestSuite 插件。