中EN

Unreal Engine Modules

  • Modules are the basic building block of UE's software architecture ... encapsulate specific editor tools, runtime features, libraries ... All projects and plugins have their own primary module by default. Unreal Engine modules are not related to C++ 20 modules.
  • Benefits: enforce code separation; compiled as separate compilation units (only changed modules recompile); linked in a dependency graph, IWYU; control load/unload at runtime; include/exclude per platform.
  • Setup: directory in Source with module name; [ModuleName].Build.cs; Private and Public subfolders; [ModuleName]Module.cpp in Private; configure in .uproject/.uplugin (name, type, platforms, loading phase); list as dependency in other Build.cs; regenerate project files whenever Build.cs changes or files move.
  • The Unreal build system builds projects according to Target.cs files and Build.cs files, not according to the IDE solution files ... UBT will ignore it when compiling.
  • Build.cs: class inherits ModuleRules; PublicDependencyModuleNames if classes from a module are used publicly (public .h); PrivateDependencyModuleNames if used only in .cpp. Private dependencies are preferred ... reduce compile times. Forward declarations allow more private dependencies.
  • Private/Public folders control availability to other modules, unrelated to C++ access specifiers. Headers in Private not exposed outside the module. Game primary module at the end of the dependency chain need not use them.
  • IMPLEMENT_MODULE(FDefaultModuleImpl, ModuleTest); — class extending IModuleInterface; startup/shutdown functions.
  • UBT only compiles modules found in the dependency chain for your project.
  • .uproject/.uplugin "Modules" list: Name, Type (most common Runtime and Editor), LoadingPhase (Default; plugins may need PreDefault if editor can't find C++ classes). Include/Exclude lists for Platforms, Targets (Game, Server, Client, Editor, Program), TargetConfigurations (Debug, DebugGame, Development, Shipping, Test), Programs.
  • Within a LoadingPhase the module loading order is not deterministic; use LoadModule / LoadModuleChecked to ensure order; GetModule for optional.

引用这一章的笔记

输入关键词开始搜索

滚轮或双指缩放 · 拖动平移 · 双击放大 / 还原