Core Concepts and Origins
GameFeature is a framework introduced in UE5 that supports dynamically loading gameplay. It uses a plugin-based architecture to deliver “plug-and-play” modular game features. Epic developed this framework to address the following challenges faced by modern games (especially live-service games):
- Frequent content updates: e.g., seasonal content rotation in Fortnite, requiring dynamic addition/removal of game features
- Parallel development needs: new features can be developed in parallel with the current version without breaking the core game
- Hot-plug capability: dynamically enable/disable features at runtime without repackaging the entire game
You can read Modular Gameplay Plugins in Unreal Engine together with this plugin.
System Architecture and Core Components
graph TD
A[UGameFeaturesSubsystem<br/>全局管理器] --> B[UGameFeaturePluginStateMachine<br/>状态机]
B --> C[EGameFeaturePluginState<br/>状态枚举]
A --> D[UGameFeatureData<br/>数据配置]
D --> E[UGameFeatureAction<br/>动作列表]
E --> F[AddComponent/AddWidget<br/>具体Action实现]
A --> G[UGameFeaturesProjectPolicies<br/>策略控制]
G --> H[Load/Client/Server模式]
F --> I[UGameFrameworkComponentManager<br/>组件管理]
I --> J[Receiver注册机制]
Core Class Responsibilities
| Class Name | Inheritance | Responsibility |
|---|---|---|
UGameFeaturesSubsystem | UEngineSubsystem | Global singleton; manages the lifecycle of all GameFeatures and provides external APIs |
UGameFeaturePluginStateMachine | UObject | One State Machine per GameFeature; handles state transitions |
UGameFeatureData | UPrimaryDataAsset | Configuration asset; defines the list of Actions to execute for this GameFeature |
UGameFeatureAction | UObject | Base class for actions; defines operations executed at specific lifecycle stages |
UGameFeaturesProjectPolicies | UObject | Policy class; controls loading rules (Client/Server/editor environments) |
UGameFrameworkComponentManager | UGameInstanceSubsystem | Component management system; handles dynamic AddComponent |
Lifecycle State Machine
The GameFeature lifecycle is strictly managed by a State Machine. Each GameFeaturePlugin corresponds to a UGameFeaturePluginStateMachine instance, stored in UGameFeaturesSubsystem::GameFeaturePluginStateMachines (TMap<FString, StateMachine>).
Core State Definitions
stateDiagram-v2
[*] --> Installed: 发现插件
Installed --> Registered: Load/Register
Registered --> Loaded: 预加载资源
Loaded --> Active: Activate
Active --> Loaded: Deactivate
Loaded --> Registered: Unload
Registered --> Installed: Unregister
Active --> [*]: Terminal(释放内存)
Installed --> [*]: Terminal
note right of Active
完全激活状态
Actions正在执行
对游戏产生影响
end note
note left of Installed
仅在硬盘上存在
Content浏览器不可见
end note
Detailed State Description
| State | English Identifier | Description | Asset Visibility |
|---|---|---|---|
| Installed | Installed | Plugin is in local storage and not yet registered with AssetManager | ❌ Not shown in Content |
| Registered | Registered | Plugin assets are known and scanned into AssetManager but not yet loaded | ✅ Browsable but not loaded |
| Loaded | Loaded | Plugin loaded into memory, registered in the game but not activated | ✅ Loaded |
| Active | Active | Fully activated; Actions are executing and affecting Gameplay | ✅ Running |
State Transition API
| |
State Machine Internal Implementation
State transitions are implemented through ChangeGameFeatureDestination:
| |
Each state inherits from FGameFeaturePluginState and includes:
BeginState(): called when entering the stateUpdateState(): updates every frame (checks conditions to advance to the next state)TryCancelState(): attempts to cancel the current stateEndState(): called when leaving the state
Transitional States: There are intermediate transition states between states (such as Registering, Loading, Activating, etc.) used to handle asynchronous asset loading.
Hands-on: Creating Your First GameFeature
Prerequisites: Enable Required Plugins
Two plugins must be enabled at the same time:
- GameFeatures: implements Action execution and GameFeature loading
- ModularGameplay: provides implementation support for AddComponent
Path: 编辑(Edit) → 插件(Plugins) → search and enable
Step 1: Create a GameFeature Plugin
- Open the Plugins window and click
+ 新建插件 - Select the
Game Feature (with C++)Template - Name the plugin (e.g.,
MyBattleFeature) - ⚠️ Key constraint: Do not change the default directory; it must be placed under
Plugins/GameFeatures! The source code hard-codes detection of only this directory
Automatically generated after creation:
| |
⚠️ Key constraint: The GameFeatureData asset name must exactly match the plugin name!
Step 2: Configure AssetManager
Automatic configuration: Creating a GameFeature through the editor automatically configures AssetManager.
Manual configuration (if copying a GameFeature from elsewhere):
- Open
项目设置(Project Settings)→Asset Manager - Add a Primary Asset Type:
- Primary Asset Type:
GameFeatureData - Asset Base Class:
GameFeatureData - Directories: Add the
Plugins/GameFeatures/path
- Primary Asset Type:
⚠️ Required configuration: GameFeature strongly relies on AssetManager’s asset discovery mechanism. If not configured, a warning will appear when the editor starts, and it will not work properly.
Step 3: Configure Actions
Double-click MyBattleFeature.uasset to open the configuration panel:
| Setting | Description |
|---|---|
| Initial State | Default target state when the editor starts |
| Current State | Current actual state (switched at runtime) |
| Actions | Array of actions to execute when this GameFeature is activated |
Common Built-in Actions
| Action Type | Function | Use Case |
|---|---|---|
AddComponent | Dynamically add a component to a specified Actor class | Add ability components, animation components |
AddWidget | Add a UI widget to the HUD | Add health bars, minimap |
AddDataRegistry | Add a data registry | Configuration table extension |
AddGameplayCue | Add a GameplayCue | VFX extension |
Configuration example (AddComponent):
- Actor Class:
ACharacter(target Actor base class) - Component Class:
UMyBattleSkillComponent(component to add) - Server/Client: choose server-only, client-only, or both
⚠️ Note: In the Active state, the Edit Plugin button cannot be clicked. After editing GameFeatureData, change Current State to Installed and then back to Active to reload, or simply restart the editor.
Step 4: Register the Actor as a Receiver
For AddComponent to take effect, the target Actor must be registered as a Receiver:
| |
⚠️ Key constraint: Forgetting to call AddReceiver is the most common issue during debugging—the Action is configured but the Actor does not respond!
Simplified approach: Inherit from the base classes provided by ModularGameplayActors, which already have Receiver registration built in:
AModularCharacterAModularPlayerControllerAModularGameStateAModularGameMode- etc…
Step 5: Activate at Runtime
Editor Method
Directly switch the Current State slider in the GameFeatureData asset panel: Installed → Registered → Loaded → Active
C++ Runtime API
| |
⚠️ Note: Result.GetError() returns an empty string on success; printing it directly may cause a crash. Check Result.HasError() first.
Console Commands (Debug)
| |
Deep Dive into Core Mechanisms
How AddComponent Works
sequenceDiagram
participant GFCM as GameFrameworkComponentManager
participant GF as GameFeature
目标Actor->>GFCM: AddReceiver(this)
GFCM->>GFCM: 添加到Receiver列表
GF->>GFCM: AddComponentRequest(ActorClass, ComponentClass)
GFCM->>GFCM: RequestTrackingMap[Key]++ (引用计数)
alt Actor已初始化
GFCM->>目标Actor: CreateComponentOnInstance()
GFCM->>GFCM: ComponentClassToComponentInstanceMap[ComponentClass].Add(Instance)
else Actor未生成
GFCM->>GFCM: 等待Actor生成时再创建
end
GF->>GFCM: RemoveComponentRequest() (Deactivate时)
GFCM->>GFCM: RequestTrackingMap[Key]--
alt 引用计数==0
GFCM->>GFCM: 查找ComponentClassToComponentInstanceMap
GFCM->>目标Actor: 销毁该Component的所有Instance
end
Reference Counting Mechanism: Multiple GameFeatures can request the same ComponentClass to be added to the same ActorClass, and the lifecycle is managed through reference counting.
Deferred Registration Support: Even after a GameFeature is already activated, if a new Actor calls AddReceiver later, it can immediately receive the ExtensionAdded event and have components created.
ExtensionHandler Mechanism (Non-Component Extensions)
Used to listen for Actor lifecycle events instead of directly adding components:
| |
Asset Loading Flow
In the Registered state, based on PrimaryAssetTypesToScan configured in GameFeatureData:
| |
In the Unregistering state, RemoveGameFeatureFromAssetManager is executed in reverse to unload assets.
Advanced Usage and Extensions
Custom GameFeatureAction
Inherit from UGameFeatureAction to implement custom logic:
| |
Custom ProjectPolicies
Create a policy class to control loading rules (e.g., load different GameFeatures on Client/Server):
| |
Configuration path: 项目设置 → GameFeatures → Game Features Manager Class
Lyra Project Best Practices
The Lyra sample project demonstrates production-grade usage of GameFeature:
UI Extension Pattern:
| |
Common Issues and Debugging Tips
Must-Check List
| Symptom | Possible Cause | Solution |
|---|---|---|
| GameFeature not shown in Content | Not in the Plugins/GameFeatures directory | Move the plugin to the correct directory |
| AssetManager error | GameFeatureData scan path not configured | Check AssetManager settings |
| AddComponent does not respond | Actor did not call AddReceiver | Add Receiver registration in BeginPlay |
| Validation fails after renaming Blueprint | GameFeature references the old name (UE5.1 Bug) | Recompile + save, or roll back to 5.0.3 |
| Runtime loading fails | Incorrect PluginURL | Use GetPluginURLByName to get the correct URL |
| Callback crash | Calling Result.GetError() on success | Check Result.HasError() first |
Debug Commands
| |
Best Practices Summary
- Directory structure: Strictly keep the
Plugins/GameFeatures/path and do not change the GameFeatureData name - State management: Understand State Machine transitions and avoid editing configuration in the Active state
- Receiver registration: All Actors that need dynamically added Components must properly register/remove the Receiver
- Asset management: Configure PrimaryAssetType scanning reasonably to avoid loading unnecessary assets
- Network compatibility: Use
GetGameFeatureLoadingModeto distinguish Client/Server loading policies - Version Control: GameFeature plugins should be under independent Version Control to facilitate parallel development and hot updates
- Error handling: In asynchronous API callbacks, always check
Result.HasError()before accessing error information
With the GameFeature framework, truly modular and service-oriented game development can be achieved, making the technical implementation of “Games as a Service” (GaaS) practical and feasible.