AbilityTask 是 Gameplay Ability System(GAS)框架的核心组件之一,用于处理能力(Ability)执行过程中的异步操作。它允许开发者在能力激活后创建可中断、可暂停的任务,处理如动画播放、特效生成、输入响应等耗时或需要等待的操作。
example:比如下方的两个不同时态的接口
virtual void Activate() override;
virtual void OnDestroy(bool bInOwnerFinished) override;
AbilitySystemComponent
(简称 ASC)是 Gameplay Ability System(GAS)的核心组件,负责处理游戏中的能力(Ability)、属性(Attribute)、效果(Gameplay Effect)等核心机制。它是连接角色与 GAS 系统的桥梁,几乎所有 GAS 相关的功能都需要通过它来实现。
example:
// 在角色类中声明ASC
UPROPERTY(VisibleAnywhere, Category = "GAS")
UAbilitySystemComponent* AbilitySystemComponent;
virtual UAbilitySystemComponent* GetAbilitySystemComponent() const override;
// 示例:授予单个能力
FGameplayAbilitySpec AbilitySpec(UMyGameplayAbility::StaticClass());
AbilitySystemComponent->GiveAbility(AbilitySpec);
// 示例:给自己应用一个buff
UGameplayEffect* BuffEffect = LoadObject<UGameplayEffect>(nullptr, TEXT("/Game/Effects/GE_SpeedBoost"));
if (BuffEffect)
{
FGameplayEffectContextHandle Context = AbilitySystemComponent->MakeEffectContext();
FGameplayEffectSpecHandle Spec = AbilitySystemComponent->MakeOutgoingSpec(BuffEffect, 1.0f, Context);
AbilitySystemComponent->ApplyGameplayEffectSpecToSelf(*Spec.Data.Get());
}
处理属性变化
在UAttributeSet中重写PostGameplayEffectExecute,处理属性修改后的逻辑(如生命值归零时触发死亡)。