虚拟实验室-Unreal 版本

虚拟实验室的Unreal 版本,第一个版本主要是以《探究通电螺线管外部的磁场分布》颗粒为例,设计和开发一个正式版本。


UE-模块(Module)

<p>[TOC]</p> <table> <thead> <tr> <th>作者</th> <th>QFord</th> </tr> </thead> <tbody> <tr> <td>更新日期</td> <td>2024-6-23</td> </tr> </tbody> </table> <h1>背景</h1> <p>虚拟实验室的UE版本,在组件开发过程中,需要使用到很多公共方法,这些方法很多是来自于基于Unity引擎开发的xLua或者C#。 而上述的公共方法需要组织下,以便<strong>管理、重用、扩展和维护</strong>(而不是全部放置在主模块内),因此我们可以使用<strong>模块</strong>来实现。</p> <h1>模块介绍</h1> <p><strong>模块</strong>(<strong>Modules</strong>) 是 <strong>虚幻引擎</strong>(<strong>UE</strong>) 的软件架构的基本构建块。它们在独立的代码单元中封装了具体的编辑器工具、运行时功能、库或其他功能。 &gt; 虚幻引擎模块 与 C++ 20的模块无关。</p> <h1>使用模块的好处</h1> <ul> <li> <p>模块会强制实施良好的代码分离,可用于封装功能并隐藏代码的内部成分。</p> </li> <li> <p>模块编译为单独的编译单元。这意味着,只有已更改的模块才需要编译,较大项目的编译时间会显著缩短。</p> </li> <li> <p>模块在依赖性图表中链接在一起,并且仅允许实际使用的代码包含头文件,以符合<a href="https://dev.epicgames.com/documentation/zh-cn/unreal-engine/include-what-you-use-iwyu-for-unreal-engine-programming">Include What You Use (IWYU)</a>标准。这意味着,你的项目中未使用的模块将安全地排除在编译之外。</p> </li> <li> <p>你可以控制在运行时何时加载和卸载具体的模块。这样一来,可以管理哪些系统可用并激活,从而优化项目的性能。</p> </li> <li>你可以基于特定条件(例如,项目是为哪个平台编译的),在你的项目中纳入或排除模块。</li> </ul> <h1>如何创建模块</h1> <p>请参考[官方文档:创建Gameplay模块](<a href="https://dev.epicgames.com/documentation/zh-cn/unreal-engine/how-to-make-a-gameplay-module-in-unreal-engine">https://dev.epicgames.com/documentation/zh-cn/unreal-engine/how-to-make-a-gameplay-module-in-unreal-engine</a> &quot;官方文档:创建Gameplay模块&quot;)</p> <h1>项目样例</h1> <p>我们在virtual-lab-unreal项目中,新建了第一个自定义模块:LuaToUnreal。</p> <h1>注意点</h1> <ol> <li>新建模块、修改 [ModuleName].Build.cs 文件 或 在文件夹之间移动源文件,就需要为IDE生成解决方案sln文件。可选的方式有三种: &lt;span style=&quot;color: red;&quot;&gt;a. 通过右键点击项目的 .uproject 文件重新生成sln并编译(生成前,最后清理下非版本管理的临时文件)。&lt;/span&gt; b. 运行 GenerateProjectFiles.bat. C. 在虚幻编辑器中,点击 文件(File) &gt; 刷新(Refresh) Visual Studio 项目(Project)。</li> </ol> <h1>FAQ</h1> <ol> <li> <p>PublicDependencyModuleNames 和PrivateDependencyModuleNames 的区别?</p> <p>官方文档的解释不好理解,我这里建议使用AI Hub的Unreal开发专家 Bot来回答。</p> <p><strong>提示词:</strong>unreal模块中的PublicDependencyModuleNames 和PrivateDependencyModuleNames 的区别,请采用好理解的方式来介绍,最好使用比喻或者类比的方式来描述。 <strong>回答:</strong> <img src="https://www.showdoc.com.cn/server/api/attachment/visitFile?sign=d9c72e20b1fdd77f13ce39115220a270&amp;amp;file=file.png" alt="" /> <img src="https://www.showdoc.com.cn/server/api/attachment/visitFile?sign=4e3b5a92bc7a80462f1db615c2c50d36&amp;amp;file=file.png" alt="" /></p> </li> </ol> <h1>问题处理</h1> <p><strong>问题描述:</strong>在重新生成sln文件的时候报错,弹窗的报错内容如下: Running E:/Program Files/Epic Games/UE_5.4/Engine/Build/BatchFiles/Build.bat -projectfiles -project=&quot;E:/virtual-lab-unreal/VLabUE/VLabUE.uproject&quot; -game -rocket -progress -log=&quot;E:\virtual-lab-unreal\VLabUE/Saved/Logs/UnrealVersionSelector-2024.06.19-20.07.11.log&quot; Using bundled DotNet SDK version: 6.0.302 Running UnrealBuildTool: dotnet &quot;....\Engine\Binaries\DotNET\UnrealBuildTool\UnrealBuildTool.dll&quot; -projectfiles -project=&quot;E:/virtual-lab-unreal/VLabUE/VLabUE.uproject&quot; -game -rocket -progress -log=&quot;E:\virtual-lab-unreal\VLabUE/Saved/Logs/UnrealVersionSelector-2024.06.19-20.07.11.log&quot; Cannot use file stream for [E:\Program Files\Epic Games\UE_5.4\Engine\Binaries\DotNET\UnrealBuildTool\UnrealBuildTool.deps.json]: No such file or directory Could not resolve CoreCLR path. For more details, enable tracing by setting COREHOST_TRACE environment variable to 1 <strong>解决方案:</strong>Rebuild UnrealBuildTool.sln后解决。这个sln的路径取决于UE的安装路径,我的是在E:\Program Files\Epic Games\UE_5.4\Engine\Source\Programs\UnrealBuildTool</p> <h1>参考资料</h1> <p>[官方文档:创建Gameplay模块](<a href="https://dev.epicgames.com/documentation/zh-cn/unreal-engine/how-to-make-a-gameplay-module-in-unreal-engine">https://dev.epicgames.com/documentation/zh-cn/unreal-engine/how-to-make-a-gameplay-module-in-unreal-engine</a> &quot;官方文档:创建Gameplay模块&quot;) [官方文档:虚幻引擎模块(Unreal Engine Modules)](<a href="https://dev.epicgames.com/documentation/zh-cn/unreal-engine/unreal-engine-modules">https://dev.epicgames.com/documentation/zh-cn/unreal-engine/unreal-engine-modules</a> &quot;虚幻引擎模块(Unreal Engine Modules)&quot;)</p>

页面列表

ITEM_HTML