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.cppin 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.csfiles andBuild.csfiles, not according to the IDE solution files ... UBT will ignore it when compiling. - Build.cs: class inherits ModuleRules;
PublicDependencyModuleNamesif classes from a module are used publicly (public .h);PrivateDependencyModuleNamesif 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 extendingIModuleInterface; 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/LoadModuleCheckedto ensure order;GetModulefor optional.