3.2 KiB
3.2 KiB
title: "GAS (Gameplay Ability System)"
type: concept
tags: [unreal-engine, networking, multiplayer, ue5, abilities]
sources: ["unreal-multiplayer-architect", "unreal-systems-engineer"]
last_updated: 2026-04-26
## Additional Sources
Gameplay Ability System(GAS)是 UE5 的可扩展技能与属性框架,通过 UGameplayAbility、UAttributeSet、UAbilitySystemComponent 实现网络就绪的技能系统。UnrealSystemsEngineer 补充:所有 Tick 逻辑必须 C++;FGameplayTag 优于字符串标识符;通过 UPROPERTY(ReplicatedUsing=OnRep_Health) + GAMEPLAYATTRIBUTE_REPNOTIFY 宏实现属性复制。
## Core Components
- UAbilitySystemComponent:GAS 核心组件,管理技能和属性,必须正确配置网络复制
- UGameplayAbility:可激活的技能类,支持网络预测和复制
- FGameplayEffectContext:技能效果上下文,携带命中结果、来源和自定义数据
- FPredictionKey:预测键,标记可预测的能力和属性变更,支持服务器确认或回滚
- UAttributeSet:属性集,包含可复制的游戏属性(生命值、能量等)
## Network Integration (Dual Init Path)
GAS 在多人游戏中必须实现双路径初始化:
cpp // 服务器路径 — PossessedBy 在 Actor 被 Controller 拥有时调用 void AMyCharacter::PossessedBy(AController* NewController) { Super::PossessedBy(NewController); AbilitySystemComponent->InitAbilityActorInfo(GetPlayerState(), this); } // 客户端路径 — OnRep_PlayerState 在 PlayerState 复制到达时调用 void AMyCharacter::OnRep_PlayerState() { Super::OnRep_PlayerState(); AbilitySystemComponent->InitAbilityActorInfo(GetPlayerState(), this); }
## Network Prediction in GAS
- FPredictionKey:标记所有预测变更,服务器确认后生效
- 客户端预测技能激活和属性变更
- 服务器验证并广播 GameplayEffect 到所有客户端
- 验证失败时服务器回滚客户端预测
## Best Practices
- 双路径初始化:必须在 PossessedBy 和 OnRep_PlayerState 两个入口点初始化 GAS
- AttributeSet 复制:使用 UPROPERTY(Replicated) 让属性在服务器和客户端同步
- 预测管理:高频技能必须正确设置 NetDeltaFrequency 避免带宽爆炸
- 预测键作用域:FPredictionKey 必须在能力激活时生成并传递给所有子操作
## Connection to Other Concepts
- Actor Replication — GAS 依赖 Actor 复制机制同步属性和状态
- Network Prediction — GAS 内置网络预测支持(FPredictionKey)
- Server-Authoritative Model — 服务器权威验证技能激活请求
## Relationship to Agent
UnrealMultiplayerArchitect 强调:GAS 网络集成必须从双路径初始化开始,测试必须在 150ms 模拟延迟下验证技能激活,"Profile GAS replication overhead" 是网络优化的关键步骤。
UnrealSystemsEngineer 补充:系统架构师负责 UGameplayAbility/UAttributeSet C++ 实现和 BlueprintCallable 暴露;Tick 依赖逻辑必须 C++(即使是技能冷却检查);AttributeSet 使用 FGameplayAttributeData + GAMEPLAYATTRIBUTE_REPNOTIFY 宏保证复制安全。
## Aliases
- Gameplay Ability System
- UE5 GAS
- AbilitySystemComponent
- FPredictionKey
- GameplayEffect
- AttributeSet