بنقرة واحدة
module-and-build-system
Structure Unreal C++ into modules and configure the build with *.Build.cs
التثبيت باستخدام Codex أو Claude انسخ هذا Prompt والصقه في Codex أو Claude أو مساعد آخر ليراجع صفحة Skill ويثبّتها لك.
القائمة
Structure Unreal C++ into modules and configure the build with *.Build.cs
التثبيت باستخدام Codex أو Claude انسخ هذا Prompt والصقه في Codex أو Claude أو مساعد آخر ليراجع صفحة Skill ويثبّتها لك.
استنادا إلى تصنيف SOC المهني
Build game UI in Unreal — UMG user widgets (UUserWidget) with the C++ lifecycle
Wire up callbacks and events in Unreal C++ using delegates — single-cast (DECLARE_DELEGATE, DECLARE_DELEGATE_RetVal, payload variables), multicast (DECLARE_MULTICAST_DELEGATE, DECLARE_TS_MULTICAST_DELEGATE), and dynamic (DECLARE_DYNAMIC_MULTICAST_DELEGATE, BlueprintAssignable, AddDynamic, RemoveDynamic). Covers all binding forms (BindUObject, AddUObject, BindLambda, AddWeakLambda, BindRaw, AddSP), execution (Execute, ExecuteIfBound, Broadcast), FDelegateHandle lifetime management, safe unbinding, and DECLARE_EVENT. Use when implementing the observer pattern, exposing C++ events to Blueprints, decoupling game systems, binding overlap/hit/ability callbacks, or debugging delegate crashes and silent no-ops.
Build and compose gameplay objects from Actors and Components in Unreal C++ — the AActor lifecycle (constructor, PostInitializeComponents, BeginPlay, Tick, EndPlay, Destroyed), the component types (UActorComponent, USceneComponent, UPrimitiveComponent), the root component and attachment, spawning actors and creating/registering components at construction or runtime, and ticking. Use when creating an actor or component, setting up a component hierarchy, attaching components, spawning actors, registering runtime components, or debugging lifecycle/ticking/ attachment/overlap issues.
Build AI in Unreal — AIController-driven pawns, Behavior Trees and Blackboards (tasks, decorators, services), the navigation system and NavMesh (MoveTo pathfinding, NavMeshBoundsVolume, NavAreas, avoidance), the Environment Query System (EQS generators, tests, C++ FEnvQueryRequest), AI Perception (sight/hearing/damage senses, ConfigureSense, OnTargetPerceptionUpdated), and StateTree (UStateTreeAIComponent). Use when creating enemy/NPC behavior, pathfinding/movement to targets, decision-making logic, environment queries for cover/flanking/positions, sensing the player, or replacing Behavior Trees with StateTree.
Animate skeletal meshes in Unreal using the AnimInstance / Animation Blueprint model — C++ UAnimInstance base class (NativeInitializeAnimation, NativeUpdateAnimation, NativeThreadSafeUpdateAnimation), AnimGraph with state machines and blend spaces, animation assets (UAnimSequence, UBlendSpace, UAnimMontage, UAnimComposite, UPoseAsset), anim notifies and notify states, montage playback and delegates, linked anim layers, Motion Matching (Pose Search plugin), and Motion Warping. Use when setting up character animation, driving locomotion blends from C++, playing montages for actions, firing gameplay events at precise animation frames (notifies), switching animation sets at runtime, or integrating the Pose Search / Motion Warping plugins.
Reference and load Unreal assets correctly — hard vs soft references (TObjectPtr vs TSoftObjectPtr/TSoftClassPtr), virtual content paths, FSoftObjectPath, async loading with FStreamableManager and FStreamableHandle, the Asset Registry for querying without loading, ConstructorHelpers::FObjectFinder, UAssetManager/primary data assets, and asset bundles. Use when choosing a reference type, fixing load hitches or cook/memory bloat from hard references, loading assets on demand (level streaming, DLC, runtime content), enumerating or filtering assets without loading, or setting up a managed primary-asset pipeline with UPrimaryDataAsset.
| name | module-and-build-system |
| description | Structure Unreal C++ into modules and configure the build with *.Build.cs |
Every Unreal C++ feature lives in a module: a directory that compiles into its own DLL
(modular builds) or static lib (monolithic builds). UnrealBuildTool (UBT) reads C#-style
*.Build.cs files (one per module) and *.Target.cs files (one per build target) to decide
what to compile and link. Most "won't compile / won't link" problems are really "wrong module
dependency" problems.
Note: UE modules are independent of C++20 language modules.
*_API symbol), "cannot open include file",
"module X not found at startup".UEnhancedInputComponent and need EnhancedInput).PublicDependencyModuleNames vs PrivateDependencyModuleNames, or the loading
phase and host type.Source/<Module>/ with <Module>.Build.cs plus Public/
(headers other modules may include) and Private/ (implementation + internal headers).<MODULE>_API macro (e.g. MYGAME_API) expands to __declspec(dllexport/dllimport)
in modular builds and to nothing in monolithic builds. Missing it on a class another module
uses → unresolved external symbol.#include its public header and (2) list that
module in your Build.cs dependencies. Both are required.*.Target.cs) describe an executable: which modules it boots with and whether
the build links them as a monolith or as separate DLLs.Build.cs/Target.cs files.
Regenerate project files any time you add, move, or rename source files.Source/MyGame/
├── MyGame.Build.cs
├── Public/ # headers exposed to other modules
│ └── MyActor.h
└── Private/ # .cpp files + internal-only headers
├── MyActor.cpp
└── MyGameModule.cpp # IMPLEMENT_PRIMARY_GAME_MODULE lives here
#include paths resolve from the Public/Private root, not the disk path:
a header at Public/Weapons/Gun.h is included as #include "Weapons/Gun.h".
Files outside these canonical folders are treated as private automatically.
*.Build.cs — ModuleRulesEach module has exactly one <Name>.Build.cs in its root. UBT compiles it at build time.
using UnrealBuildTool;
public class MyGame : ModuleRules
{
public MyGame(ReadOnlyTargetRules Target) : base(Target)
{
PCHUsage = PCHUsageMode.UseExplicitOrSharedPCHs; // required for IWYU compliance
// Types from these modules appear in THIS module's PUBLIC headers → Public
PublicDependencyModuleNames.AddRange(new string[]
{
"Core", "CoreUObject", "Engine", "InputCore"
});
// Types used only in .cpp or private headers → Private (faster builds, leaner API)
PrivateDependencyModuleNames.AddRange(new string[]
{
"EnhancedInput", "UMG", "Slate", "SlateCore"
});
// Editor-only dependencies — gate to avoid packaging bloat
if (Target.bBuildEditor)
{
PrivateDependencyModuleNames.Add("UnrealEd");
}
}
}
Key rules:
.cpp/private headers, prefer private.Build.cs (or the engine module's name).navigating-engine-source.PCHUsage = PCHUsageMode.UseExplicitOrSharedPCHs enables IWYU-safe precompiled headers.
Each .cpp must include its matching .h first, and no monolithic headers (Engine.h).See references/build-cs-reference.md for the full property list, advanced options, and third-party library integration.
*.Target.cs — TargetRulesA project normally has two: <Project>.Target.cs (Game) and <Project>Editor.Target.cs
(Editor).
using UnrealBuildTool;
public class MyGameTarget : TargetRules
{
public MyGameTarget(TargetInfo Target) : base(Target)
{
Type = TargetType.Game; // Game / Editor / Server / Client / Program
DefaultBuildSettings = BuildSettingsVersion.V5; // use engine defaults from 5.x
IncludeOrderVersion = EngineIncludeOrderVersion.Latest;
ExtraModuleNames.Add("MyGame"); // primary game module(s)
}
}
TargetType values: Game (cooked monolithic), Editor (modular with editor DLLs),
Server, Client, Program. Editor targets link modularly; Game/Server/Client link
monolithically on most platforms.
See references/target-cs-reference.md for all
TargetRules fields, link types, and build settings.
Every module needs exactly one registration macro in a single .cpp:
#include "Modules/ModuleManager.h"
// For the primary game module (name matches .uproject):
IMPLEMENT_PRIMARY_GAME_MODULE(FDefaultGameModuleImpl, MyGame, "MyGame");
// For secondary modules or plugin modules:
// IMPLEMENT_MODULE(FDefaultModuleImpl, MySecondaryModule);
FDefaultModuleImpl — empty IModuleInterface; does nothing at startup/shutdown.
(ModuleManager.h:871)FDefaultGameModuleImpl : FDefaultModuleImpl — overrides IsGameModule() to return true.
(ModuleManager.h:879)IModuleInterface and override StartupModule() /
ShutdownModule(). Use StartupModule to load dependent modules with
FModuleManager::Get().LoadModuleChecked(TEXT("MyDep")).// MyEditorModule.cpp
#include "Modules/ModuleManager.h"
#include "MyEditorModule.h"
IMPLEMENT_MODULE(FMyEditorModule, MyEditorModule)
void FMyEditorModule::StartupModule()
{
// register editor extensions, detail customizations, etc.
}
void FMyEditorModule::ShutdownModule()
{
// unregister everything registered in StartupModule
}
See references/module-cpp-and-phases.md for the full
IModuleInterface API, loading-phase details, and FModuleManager query methods.
.uproject / .uplugin"Modules": [
{
"Name": "MyGame",
"Type": "Runtime",
"LoadingPhase": "Default"
},
{
"Name": "MyGameEditor",
"Type": "Editor",
"LoadingPhase": "Default"
}
]
Type (ModuleHostType enum, ModuleDescriptor.cs:18):
| Type | Loaded in |
|---|---|
Runtime | any target using the UE runtime |
RuntimeNoCommandlet | runtime targets, except commandlets |
Editor | editor only — stripped from packaged games |
EditorNoCommandlet | editor only, not in commandlets |
Developer / DeveloperTool | builds with developer tools enabled |
ServerOnly / ClientOnly | server-only or client-only targets |
UncookedOnly | uncooked builds only |
Program | standalone programs |
LoadingPhase (ModuleLoadingPhase enum, ModuleDescriptor.cs:104):
| Phase | When |
|---|---|
EarliestPossible | as soon as GConfig is ready |
PostConfigInit | after config, before most engine systems |
PreLoadingScreen | before the loading screen fires |
PreDefault | just before Default |
Default | after game modules are loaded (standard) |
PostDefault | just after Default |
PostEngineInit | after engine is fully initialized |
None | not loaded automatically |
Most gameplay code uses Default. Plugin modules that provide factories or types needed by
other modules often use PreDefault. If the editor keeps throwing "class not found" for your
plugin, try PreDefault.
Source/<New>/ with Public/ and Private/ subdirectories.<New>.Build.cs inheriting ModuleRules, list dependencies.Private/<New>Module.cpp with IMPLEMENT_MODULE(FDefaultModuleImpl, <New>)..uproject/.uplugin Modules array.<New> to other modules' dependency lists where they consume it..uproject → Generate Visual Studio Project Files).<MODULE>_API export macrosMYGAME_API expands to __declspec(dllexport) when compiling the module and
__declspec(dllimport) when another module includes it, and to nothing in monolithic
builds. Apply it to the class keyword or individual functions:
// Export the whole class — all virtual and non-inline members cross the DLL boundary
class MYGAME_API UMyComponent : public UActorComponent { ... };
// Export only a free function
MYGAME_API void MyGlobalHelper();
Rules:
MYGAME_API to any class, function, or data symbol another module accesses._API if used externally._API on a class used by another module → unresolved external symbol at link.<MODULE>_API on a class used cross-module → unresolved external symbol.Build.cs → "cannot open include file" even though the
header exists on disk; or unresolved externals for symbols in that header.Editor-type module and guard with #if WITH_EDITOR.Build.cs or moving source files requires regenerating project files before
building, not just a Live Coding reload.FModuleManager::LoadModuleChecked in StartupModule ensures the dependency is loaded
before your module uses it. Relying on load order without this can produce intermittent
crashes when the phase is shared with other modules._API macros are empty and
DLL boundary rules don't apply; but code written without _API will fail in Editor builds
(modular). Always use the macro correctly.BuildSettingsVersion.V5 is the current recommended value in UE 5.7 (TargetRules.cs:162).
New projects generated by the engine use BuildSettingsVersion.Latest / V5.EngineIncludeOrderVersion.Latest (= Unreal5_7) in UE 5.7 (TargetRules.cs:455).bRequiresImplementModule property (default true) in ModuleRules.cs enforces the
IMPLEMENT_MODULE macro presence at link time.plugins-and-modules — packaging modules inside a .uplugin; plugin vs project module.project-structure — .uproject layout, Source/ and Config/ conventions.navigating-engine-source — finding which module owns a class or header.cpp-fundamentals — UCLASS/USTRUCT/UENUM, the reflection system.Engine source (UE 5.7, under E:\Program Files\Epic Games\UE_5.7\Engine\Source\):
C++ module system (Runtime/Core/Public/Modules/):
ModuleInterface.h — IModuleInterface: StartupModule():31, ShutdownModule():55,
SupportsDynamicReloading():64, IsGameModule():84.ModuleManager.h — FModuleManager:170, FDefaultModuleImpl:871,
FDefaultGameModuleImpl:879, IMPLEMENT_MODULE macro:933,
IMPLEMENT_PRIMARY_GAME_MODULE macro:1081/1117.Boilerplate/ModuleBoilerplate.h — PER_MODULE_BOILERPLATE:114 (new/delete overrides,
memory wrapper definitions placed in every module).UBT C# configuration (Programs/UnrealBuildTool/Configuration/):
ModuleRules.cs — ModuleRules class:103, PCHUsageMode enum:193,
PublicDependencyModuleNames:1189, PrivateDependencyModuleNames:1200.TargetRules.cs — TargetType enum:21, TargetLinkType enum:52,
DefaultBuildSettings:711, ExtraModuleNames:2654.UBT C# system (Programs/UnrealBuildTool/System/):
ModuleDescriptor.cs — ModuleHostType enum:18, ModuleLoadingPhase enum:104,
ModuleDescriptor class:161.Official docs (UE 5.7, all fetched and verified):
Deep-dive references in this skill:
ModuleRules
property catalogue, PCH modes, third-party library integration, IWYU settings.TargetRules
fields, TargetType/TargetLinkType, build settings versions, per-target editor gating.IModuleInterface
full API, FModuleManager query methods, loading phases deep-dive, startup/shutdown ordering.