Page Info
Engine Version:




模块是 UE4 的编译块。引擎作为模块的一个大集合而实现,而游戏则提供其自身的模块进行扩大。每个模块都封装了一套功能,可提供一个公共接口和编译环境(利用宏、包含路径等),以便其他模块使用。

模块通过带 .build.cs 扩展名的 C# 源文件进行声明,保存在项目的 Source 目录下。属于模块的 C++ 源代码保存在 .build.cs 文件旁,或其子目录中。每个 .build.cs 文件声明派生自 ModuleRules 基类的类,并设置属性控制器从构造函数进行编译的方式。这些 .build.cs 文件由虚幻编译工具编译,并被构造来确定整体编译环境。

.build.cs 文件的典型结构如下。

using UnrealBuildTool;
using System.Collections.Generic;

public class MyModule :ModuleRules
    public MyModule(ReadOnlyTargetRules Target) : base(Target)
        // Settings go here

Read/Write Properties

Type (ModuleType)

Type of module

BinariesSubFolder (String)

Subfolder of Binaries/PLATFORM folder to put this module in when building DLLs. This should only be used by modules that are found via searching like the TargetPlatform or ShaderFormat modules. If FindModules is not used to track them down, the modules will not be found.

OptimizeCode (CodeOptimization)

When this module's code should be optimized.

PrivatePCHHeaderFile (String)

Explicit private PCH for this module. Implies that this module will not use a shared PCH.

SharedPCHHeaderFile (String)

Header file name for a shared PCH provided by this module. Must be a valid relative path to a public C++ header file. This should only be set for header files that are included by a significant number of other C++ modules.

PCHUsage (PCHUsageMode)

Precompiled header usage for this module

bUseRTTI (Boolean)

Use run time type information

bUseAVX (Boolean)

Use AVX instructions

bEnableBufferSecurityChecks (Boolean)

Enable buffer security checks. This should usually be enabled as it prevents severe security risks.

bEnableExceptions (Boolean)

Enable exception handling

bEnableShadowVariableWarnings (Boolean)

Enable warnings for shadowed variables

bEnableUndefinedIdentifierWarnings (Boolean)

Enable warnings for using undefined identifiers in #if expressions

bFasterWithoutUnity (Boolean)

If true and unity builds are enabled, this module will build without unity.

MinSourceFilesForUnityBuildOverride (Int32)

The number of source files in this module before unity build will be activated for that module. If set to anything besides -1, will override the default setting which is controlled by MinGameModuleSourceFilesForUnityBuild

MinFilesUsingPrecompiledHeaderOverride (Int32)

Overrides BuildConfiguration.MinFilesUsingPrecompiledHeader if non-zero.

bBuildLocallyWithSNDBS (Boolean)

Module uses a #import so must be built locally when compiling with SN-DBS

IsRedistributableOverride (Nullable<Boolean>)

Redistribution override flag for this module.

bOutputPubliclyDistributable (Boolean)

Whether the output from this module can be publicly distributed, even if it has code/ dependencies on modules that are not (i.e. CarefullyRedist, NotForLicensees, NoRedist). This should be used when you plan to release binaries but not source.

WhitelistRestrictedFolders (List<String>)

List of folders which are whitelisted to be referenced when compiling this binary, without propagating restricted folder names

bEnforceIWYU (Boolean)

Enforce "include what you use" rules when PCHUsage is set to ExplicitOrSharedPCH; warns when monolithic headers (Engine.h, UnrealEd.h, etc...) are used, and checks that source files include their matching header first.

PublicIncludePathModuleNames (List<String>)

List of modules names (no path needed) with header files that our module's public headers needs access to, but we don't need to "import" or link against.

PublicDependencyModuleNames (List<String>)

List of public dependency module names (no path needed) (automatically does the private/public include). These are modules that are required by our public source files.

PrivateIncludePathModuleNames (List<String>)

List of modules name (no path needed) with header files that our module's private code files needs access to, but we don't need to "import" or link against.

PrivateDependencyModuleNames (List<String>)

List of private dependency module names. These are modules that our private code depends on but nothing in our public include files depend on.

CircularlyReferencedDependentModules (List<String>)

Only for legacy reason, should not be used in new code. List of module dependencies that should be treated as circular references. This modules must have already been added to either the public or private dependent module list.

PublicSystemIncludePaths (List<String>)

List of system/library include paths - typically used for External (third party) modules. These are public stable header file directories that are not checked when resolving header dependencies.

PublicIncludePaths (List<String>)

(This setting is currently not need as we discover all files from the 'Public' folder) List of all paths to include files that are exposed to other modules

PrivateIncludePaths (List<String>)

List of all paths to this module's internal include files, not exposed to other modules (at least one include to the 'Private' path, more if we want to avoid relative paths)

PublicLibraryPaths (List<String>)

List of system/library paths (directory of .lib files) - typically used for External (third party) modules

PublicAdditionalLibraries (List<String>)

List of additional libraries (names of the .lib files including extension) - typically used for External (third party) modules

PublicFrameworks (List<String>)

List of XCode frameworks (iOS and MacOS)

PublicWeakFrameworks (List<String>)

List of weak frameworks (for OS version transitions)

PublicAdditionalFrameworks (List<UEBuildFramework>)

List of addition frameworks - typically used for External (third party) modules on Mac and iOS

AdditionalBundleResources (List<UEBuildBundleResource>)

List of addition resources that should be copied to the app bundle for Mac or iOS

PublicAdditionalShadowFiles (List<String>)

For builds that execute on a remote machine (e.g. iOS), this list contains additional files that need to be copied over in order for the app to link successfully. Source/header files and PCHs are automatically copied. Usually this is simply a list of precompiled third party library dependencies.

PublicDelayLoadDLLs (List<String>)

List of delay load DLLs - typically used for External (third party) modules

Definitions (List<String>)

Additional compiler definitions for this module

DynamicallyLoadedModuleNames (List<String>)

Addition modules this module may require at run-time

PlatformSpecificDynamicallyLoadedModuleNames (List<String>)

Extra modules this module may require at run time, that are on behalf of another platform (i.e. shader formats and the like)

RuntimeDependencies (RuntimeDependencyList)

List of files which this module depends on at runtime. These files will be staged along with the target.

AdditionalPropertiesForReceipt (List<ReceiptProperty>)

List of additional properties to be added to the build receipt

PrecompileForTargets (PrecompileTargetsType)

Which targets this module should be precompiled for