虚幻GameAbilitySystem源码与设计解析-GameAbility

头文件

#pragma once

#include "CoreMinimal.h"
#include "UObject/ObjectMacros.h"
#include "UObject/Object.h"
#include "Templates/SubclassOf.h"
#include "GameplayTagContainer.h" //Tag容器
#include "GameplayEffectTypes.h" //Effects类型
#include "GameplayAbilitySpec.h" //
#include "GameplayEffect.h" //GE
#include "Abilities/GameplayAbilityTypes.h" //Ability的类型
#include "GameplayTaskOwnerInterface.h" //5.4的新功能大概是
#include "Abilities/GameplayAbilityTargetTypes.h"
#include "Net/Core/PushModel/PushModelMacros.h"
#include "GameplayAbility.generated.h"

//常见的前向声明
class UAbilitySystemComponent;
class UAnimMontage;
class UGameplayAbility;
class UGameplayTask;
class UGameplayTasksComponent;

官方的解释

 

/**
 * UGameplayAbility
 * 
 * 技能(能力)定义了可以被激活或触发的自定义游戏玩法逻辑。
 * 
 * 技能系统为游戏技能提供的主要特性如下:
 *  - 能否使用的功能:
 *      - 冷却时间
 *      - 消耗(法力值、耐力值等)
 *      - 等等
 * 
 *  - 网络同步支持:
 *      - 客户端/服务器之间关于技能激活的通信
 *      - 客户端对技能激活的预测
 * 
 *  - 实例化支持:
 *      - 技能可以是非实例化的(仅原生方式)
 *      - 按所有者实例化
 *      - 按执行实例化(默认方式)
 * 
 *  - 对以下方面提供基本的、可扩展的支持:
 *      - 输入绑定
 *      - 向角色“赋予”(可使用的)技能
 * 
 * 有关非实例化技能的示例,请参考 GameplayAbility_Montage:
 *  - 播放一个蒙太奇动画,并在动画播放期间对目标施加一个游戏玩法效果。
 *  - 动画播放结束后,移除该游戏玩法效果。
 * 
 * 关于网络同步支持的说明:
 *  - 非实例化技能的网络同步支持有限。
 *      - 显然,它不能有状态,因此没有可同步的属性。
 *      - 也无法在技能类上使用远程过程调用(RPC)。
 * 
 * 若要支持状态或事件的网络同步,技能必须是实例化的。这可以通过 InstancingPolicy 属性来实现。
 */

2. 辅助结构体和静态变量

struct FScopedCanActivateAbilityLogEnabler
{
    //每一个创建的GA实对象那么记录实例数量的计数器增加
    FScopedCanActivateAbilityLogEnabler() { ++LogEnablerCounter; }
    //每一个GA对象被销毁,计数器减少
    ~FScopedCanActivateAbilityLogEnabler() { --LogEnablerCounter; }
    //静态成员函数,返回有多少个实例存在
    static bool IsLoggingEnabled() { return LogEnablerCounter > 0; }

private:
    //静态成员变量
    //这是一个私有静态成员变量,用于跟踪当前有多少个 FScopedCanActivateAbilityLogEnabler 对象存在。
    //由于它是静态的,所有 FScopedCanActivateAbilityLogEnabler 对象共享同一个 LogEnablerCounter 变量。
    //私有的访问修饰符确保外部代码不能直接修改该变量,只能通过 FScopedCanActivateAbilityLogEnabler 的构造函数和析构函数来间接修改。
    static int32 LogEnablerCounter;
};

这段代码定义了一个名为 FScopedCanActivateAbilityLogEnabler 的结构体,它是一个典型的 RAII(Resource Acquisition Is Initialization,资源获取即初始化)风格的类,主要用于管理 CanActivateAbility 函数相关的日志记录的启用和禁用状态。以下是对该结构体的详细解释:

这是一个计数器类,记录有多少个类被启用

// 在某个函数中启用日志记录
void SomeFunction()
{
    FScopedCanActivateAbilityLogEnabler logEnabler;
    // 现在 LogEnablerCounter 为 1,日志记录启用
    if (FScopedCanActivateAbilityLogEnabler::IsLoggingEnabled())
    {
        // 执行日志记录相关的操作
    }
    // 函数结束,logEnabler 对象销毁,LogEnablerCounter 减 1
}
豆包给的一个有趣的例子

在上述示例中,当 SomeFunction 被调用时,FScopedCanActivateAbilityLogEnabler 对象 logEnabler 被创建,日志记录被启用。当函数执行完毕,logEnabler 对象被销毁,日志记录可能会被禁用(如果没有其他 FScopedCanActivateAbilityLogEnabler 对象存在)。这种方式确保了日志记录的启用和禁用是自动管理的,避免了手动管理可能带来的错误。

3. 委托定义(在开发中很重要

/** Notification delegate definition for when the gameplay ability ends */
//用于GA结束时的委托,多播,单参数指向UGameplayAbility类对象的指针
//这允许绑定的函数获取到结束的游戏玩法能力的具体实例,从而可以根据该实例的状态或属性进行相应的处理。
DECLARE_MULTICAST_DELEGATE_OneParam(FOnGameplayAbilityEnded, UGameplayAbility*);

/** Notification delegate definition for when the gameplay ability is cancelled */
//GA取消时候的委托,多播,无参数,不需要通知
DECLARE_MULTICAST_DELEGATE(FOnGameplayAbilityCancelled);

/** Used to notify ability state tasks that a state is being ended */
//多播委托,用于通知能力状态任务某个状态即将结束。在游戏玩法能力系统中,能力可能会有不同的状态,当某个状态结束时,就可以通过这个委托来通知相关的任务。
//参数:携带一个 FName 类型的参数,FName 在虚幻引擎里是一种高效的字符串标识符,这里用它来表示即将结束的状态的名称,方便接收通知的任务明确具体是哪个状态结束了。
DECLARE_MULTICAST_DELEGATE_OneParam(FOnGameplayAbilityStateEnded, FName);

//用途:这是一个普通委托,只能绑定一个函数。它的作用是延迟函数的执行,直到程序离开某个关键区域(临界区)。使用这个委托可以确保某些操作在离开临界区后再执行,避免出现竞态条件等并发问题。
//参数:该委托不携带任何参数,它主要关注的是在合适的时机执行绑定的函数,而不需要额外的上下文信息。
DECLARE_DELEGATE(FPostLockDelegate);

4. FAbilityTriggerData 结构体

定义了一个结构体,用于定义能力如何被外部事件触发,包括触发标签和触发源类型。

通过这些信息,系统可以判断在何种情况下应该触发某个特定的游戏玩法能力。

USTRUCT()
struct FAbilityTriggerData
{
    //相关的结构体代码宏
    GENERATED_USTRUCT_BODY()

    //在构造函数中,将 TriggerSource 成员变量初始化为 EGameplayAbilityTriggerSource::GameplayEvent,意味着默认的触发源类型是GE。
    FAbilityTriggerData() 
    : TriggerSource(EGameplayAbilityTriggerSource::GameplayEvent)
    {}

    /** The tag to respond to */
    //TriggerTag 是一个 FGameplayTag 类型的成员变量,用于指定GA要响应的标签。
    //在游戏玩法系统中,标签是一种轻量级的标识符,用于标记各种游戏元素或状态。
    //当系统检测到与 TriggerTag 匹配的标签出现时,可能会触发相应的能力。
    UPROPERTY(EditAnywhere, Category=TriggerData, meta=(Categories="TriggerTagCategory"))
    FGameplayTag TriggerTag;

    /** The type of trigger to respond to */
    //TriggerSource 是一个枚举类型的成员变量,使用 TEnumAsByte 进行包装,用于指定能力的触发源类型。
    //EGameplayAbilityTriggerSource::Type 是一个枚举类型,定义了不同的触发源类型,例如游戏玩法事件、输入事件等。
    UPROPERTY(EditAnywhere, Category=TriggerData)
    TEnumAsByte<EGameplayAbilityTriggerSource::Type> TriggerSource;
};

简单的例子

// 创建一个 FAbilityTriggerData 实例
FAbilityTriggerData triggerData;
triggerData.TriggerTag = FGameplayTag::RequestGameplayTag(FName("MyTriggerTag"));
triggerData.TriggerSource = EGameplayAbilityTriggerSource::GameplayEvent;

// 在能力系统中使用 triggerData 来配置能力的触发条件
来自豆包的简单例子

在上述示例中,创建了一个 FAbilityTriggerData 实例,并设置了触发标签和触发源类型。然后可以将这个实例应用到能力系统中,用于配置某个游戏玩法能力的触发条件。当系统检测到满足这些条件时,就会触发相应的能力。

5. UGameplayAbility 类

UCLASS(Blueprintable)
class GAMEPLAYABILITIES_API UGameplayAbility : public UObject, public IGameplayTaskOwnerInterface
{
    GENERATED_UCLASS_BODY()
    // ...
};

UGameplayAbility 类继承自 UObject 并实现了 IGameplayTaskOwnerInterface 接口,是一个可在蓝图中使用的类。

 
 

5.1 重要函数

public:

    // ----------------------------------------------------------------------------------------------------------------
    //
    //  重要的函数:
    //
    //  CanActivateAbility() - 这是一个常量函数,用于判断技能是否可以激活。UI 等界面可以直接调用此函数。
    //
    //  TryActivateAbility() - 尝试激活技能。会调用 CanActivateAbility() 函数。输入事件可以直接调用该函数。
    //                         - 同时处理按执行实例化的逻辑以及网络同步/预测调用。
    //
    //  CallActivateAbility() - 受保护的非虚函数。执行一些“激活前”的样板代码,然后调用 ActivateAbility() 函数。
    //
    //  ActivateAbility() - 技能的核心执行逻辑。子类需要重写此函数以实现具体的技能效果。
    //
    //  CommitAbility() - 提交资源/冷却时间等操作。ActivateAbility() 函数必须调用此函数!
    //
    //  CancelAbility() - (从外部)中断技能的执行。
    //
    //  EndAbility() - 技能执行结束。此函数旨在由技能自身调用以结束其自身的执行。
    //
    // ----------------------------------------------------------------------------------------------------------------

    // --------------------------------------
    //  访问器
    // --------------------------------------

 

    /** Returns how the ability is instanced when executed. This limits what an ability can do in its implementation. */
    //返回技能在执行时的实例化方式。这会限制技能在其实现过程中所能进行的操作。
    EGameplayAbilityInstancingPolicy::Type GetInstancingPolicy() const;

    /** How an ability replicates state/events to everyone on the network */
    //获取网络复制策略
    EGameplayAbilityReplicationPolicy::Type GetReplicationPolicy() const
    {
        return ReplicationPolicy;
    }

    /** Where does an ability execute on the network? Does a client "ask and predict", "ask and wait", "don't ask (just do it)" */
    //获取网络执行策略
    EGameplayAbilityNetExecutionPolicy::Type GetNetExecutionPolicy() const
    {
        return NetExecutionPolicy;
    }

    /** Where should an ability execute on the network? Provides protection from clients attempting to execute restricted abilities. */
    //网络安全策略
    EGameplayAbilityNetSecurityPolicy::Type GetNetSecurityPolicy() const
    {
        return NetSecurityPolicy;
    }
没什么用的部分
   都带UFUNCTION蓝图可用 
  //返回与此GA相关联的角色信息,其中包含指向有用对象的缓存指针 FGameplayAbilityActorInfo GetActorInfo() const; //返回拥有此GA的角色(Actor),该角色可能没有实际的物理位置。 AActor* GetOwningActorFromActorInfo() const;

//返回正在执行此GA的实体角色(Actor)。该返回值可能为空。 AActor* GetAvatarActorFromActorInfo() const; //这是一个供GA使用的便捷方法,用于获取骨骼网格体组件,这对于需要进行瞄准操作的GA十分有用。 USkeletalMeshComponent* GetOwningComponentFromActorInfo() const; //返回正在激活此GA的AS组件。 UAbilitySystemComponent* GetAbilitySystemComponentFromActorInfo() const;

感觉似乎不是太常用

    /** The ability is considered to have these tags. */
    //该GA被认为具有这些标签。
    const FGameplayTagContainer& GetAssetTags() const;

    /** Gets the current actor info bound to this ability - can only be called on instanced abilities. */
    //获取绑定到此GA的当前角色信息 —— 此操作仅可对实例化技能调用。
    const FGameplayAbilityActorInfo* GetCurrentActorInfo() const;

    /** Gets the current activation info bound to this ability - can only be called on instanced abilities. */
    //获取绑定到此GA的当前激活信息 —— 此方法仅能在已实例化的技能上调用。 
    FGameplayAbilityActivationInfo GetCurrentActivationInfo() const;

    /** Gets the current activation info bound to this ability - can only be called on instanced abilities. */
    //获取绑定到该GA的当前激活信息 —— 此操作仅适用于已实例化的技能(即只能对实例化的GA调用此方法)。 
    FGameplayAbilityActivationInfo& GetCurrentActivationInfoRef()
    {
        checkf(IsInstantiated(), TEXT("%s: GetCurrentActivationInfoRef cannot be called on a non-instanced ability. Check the instancing policy."), *GetPathName());
        return CurrentActivationInfo;
    }
激活信息

实际上都是获取实例指针 Spec和Spechandle都是需要解释的重要概念

    //获取当前的技能实例句柄(AbilitySpecHandle)—— 此操作仅能在已实例化的技能上调用。
    //在游戏开发尤其是使用虚幻引擎的技能系统时,AbilitySpecHandle 是一个用于标识特定技能实例的句柄,通过它可以方便地对技能进行管理和操作。
    //这里强调只能在实例化技能上调用获取该句柄的方法,
    //是因为非实例化技能没有这样独立的、可标识的实例,也就不存在对应的句柄。
    //************非常重要****************
    FGameplayAbilitySpecHandle GetCurrentAbilitySpecHandle() const;

    //检索此技能的实际技能(AbilitySpec)。此操作仅可在已实例化的技能上调用。
    //解释
    //在游戏开发的技能系统语境里,AbilitySpec 包含了技能的详细配置信息,比如技能等级、输入绑定等。
    //只有实例化的技能才拥有独立的、可获取的 AbilitySpec,非实例化技能由于不具备独立的实例状态,所以不能调用该方法来获取 AbilitySpec。
    FGameplayAbilitySpec* GetCurrentAbilitySpec() const;

GE的Handle和Spec

    //检索授予此技能的游戏玩法效果(GameplayEffect)的效果上下文(EffectContext)。此操作仅可在已实例化的技能上调用。
    //在游戏开发中,尤其是涉及技能系统时,GameplayEffect 可以用来授予角色技能。而 EffectContext 则包含了与该效果相关的额外信息,例如伤害来源、目标对象等上下文数据。
    //因为非实例化技能没有独立的状态和执行上下文,所以只有实例化的技能才能获取授予它的 GameplayEffect 的 EffectContext 。
    UFUNCTION(BlueprintCallable, Category = Ability)
    FGameplayEffectContextHandle GetGrantedByEffectContext() const;

    //根据我们的所有者(拥有该技能的对象)以及一个可选的目标数据,生成一个游戏玩法效果上下文句柄(GameplayEffectContextHandle)。 
    UFUNCTION(BlueprintCallable, Category = Ability)
    virtual FGameplayEffectContextHandle GetContextFromOwner(FGameplayAbilityTargetDataHandle OptionalTargetData) const;

    //根据指定的角色信息返回一个效果上下文。
    virtual FGameplayEffectContextHandle MakeEffectContext(const FGameplayAbilitySpecHandle Handle, const FGameplayAbilityActorInfo *ActorInfo) const;

太重要以至于不得不单独拿出来

    //这是一个供技能使用的便捷方法,用于获取传出的游戏玩法效果规格(例如,将其传递给投射物,以便投射物击中目标时应用这些效果)。
    //在游戏开发中,技能常常会产生各种游戏玩法效果(Gameplay Effect),比如伤害、减速、眩晕等。这些效果需要有具体的规格(Spec)来定义其属性,如伤害值、持续时间等。
    //“outgoing gameplay effect specs” 指的是从技能发出、准备应用到目标上的效果规格。这个便捷方法可以让技能方便地获取这些规格。
    //以投射物为例,当技能发射一个投射物时,可能希望投射物在击中目标时应用某些效果,比如火焰伤害、中毒效果等。通过这个方法,
    //技能可以获取这些效果规格,并将其传递给投射物,这样投射物在击中目标时就能正确地应用这些效果。
    //**************************************************************非常常用的东西************************************************************************//
    UFUNCTION(BlueprintCallable, Category=Ability)
    FGameplayEffectSpecHandle MakeOutgoingGameplayEffectSpec(TSubclassOf<UGameplayEffect> GameplayEffectClass, float Level=1.f) const;

    //上述函数的原生版本
    //不支持BP的版本
    virtual FGameplayEffectSpecHandle MakeOutgoingGameplayEffectSpec(const FGameplayAbilitySpecHandle Handle, const FGameplayAbilityActorInfo* ActorInfo, const FGameplayAbilityActivationInfo ActivationInfo, TSubclassOf<UGameplayEffect> GameplayEffectClass, float Level = 1.f) const;
    //把技能的标签添加到游戏玩法效果规格中,意味着让这个效果带有该技能的一些特性信息。这样在后续处理效果时,
    //可以根据这些标签来进行不同的逻辑判断,例如根据标签决定是否触发额外的效果,或者是否对特定类型的目标生效等。
    //**************************************************************非常常用的东西************************************************************************//
    bool IsActive() const;

    //这个技能是由触发数据(TriggerData)触发的,还是通过输入(比如玩家按键等操作)或游戏代码显式触发的呢?
    bool IsTriggered() const;

接下来的似乎不太重要

    /** Is this ability triggered from TriggerData (or is it triggered explicitly through input/game code) */
    //这个技能是由触发数据(TriggerData)触发的,还是通过输入(比如玩家按键等操作)或游戏代码显式触发的呢?
    bool IsTriggered() const;

    /** Is this ability running on a a predicting client, this is false in single player */
    //这个技能是否正在预测型客户端上运行?在单人游戏中此值为 false。
    //这里提到的 “预测型客户端(predicting client)” 就是指使用了客户端预测机制的客户端。如果技能在这样的客户端上运行,就可以利用客户端预测来优化技能表现。
    //而在单人游戏中,不存在客户端和服务器之间的交互以及客户端预测的需求,所以这个判定条件就会是 false。
    bool IsPredictingClient() const;

    /** True if this is on the server and is being executed for a non-local player, false in single player */
    //如果此操作发生在服务器端,并且是为非本地玩家执行的,则返回 true;在单人游戏中返回 false。
    bool IsForRemoteClient() const;
View Code

很重要的功能

    //如果当前处于服务器端或者是单人游戏环境,该条件为真。
    bool HasAuthority(const FGameplayAbilityActivationInfo* ActivationInfo) const;

    UFUNCTION(BlueprintCallable, BlueprintPure = false, Category = Ability, DisplayName = "HasAuthority", Meta = (ExpandBoolAsExecs = "ReturnValue"))
    //非BP版本
    bool K2_HasAuthority() const;

    //如果我们拥有控制权(即处于权威状态),或者我们有一个预期有效的有效预测键,那么该条件为真。
    bool HasAuthorityOrPredictionKey(const FGameplayAbilityActorInfo* ActorInfo, const FGameplayAbilityActivationInfo* ActivationInfo) const;

用于判断实例化的重要function

    //如果该对象已被实例化,则此条件为 true;对于蓝图而言,此条件始终为 true。
    //蓝图的特殊性
    //在虚幻引擎等游戏开发工具中,蓝图是一种可视化的脚本编程方式。蓝图本质上可以看作是已经实例化好的对象,它们自带一些默认的配置和行为,并且可以直接在场景中使用。
    //所以对于蓝图来说,“是否已实例化” 这个判断条件始终为 true,因为蓝图本身就已经是具体的实例,不需要像普通类那样再进行显式的实例化操作。
    bool IsInstantiated() const;

几个非常重要的委托

    //这是一个关于技能结束的通知。该通知通过调用 TryActivateAbility 方法来设置。
    //在游戏开发的技能系统中,技能通常有激活和结束等不同的状态。当技能从激活状态转变为结束状态时,系统需要发出相应的通知,以便游戏的其他部分(如界面显示、音效播放、状态更新等)做出响应。
    //TryActivateAbility 是一个常用的用于尝试激活技能的方法。在技能激活之后,当技能满足结束条件(比如技能持续时间结束、被打断等),
    //就会触发这个技能结束的通知。通过这个通知,开发者可以在技能结束时执行一些特定的逻辑,例如停止技能相关的动画、回收资源、更新角色状态等。
    FOnGameplayAbilityEnded OnGameplayAbilityEnded;

    //这是一个技能结束的通知,并且该通知附带了关于技能是如何结束的相关数据。
    //在游戏开发里,技能系统通常会涉及技能的激活、执行以及结束等不同阶段。当技能结束时,系统发送的通知除了告知技能已结束这一基本信息外,还会携带技能结束方式的相关数据。
    //这些关于技能结束方式的数据可能包含多种情况,比如:
    //正常结束:技能按照预设的持续时间自然完成,通知数据里可能会包含技能实际持续的时长。
    //被打断结束:技能在执行过程中被其他事件打断,如角色受到控制效果、被攻击等,通知数据可能会说明打断技能的具体原因和来源。
    //条件不满足结束:技能执行过程中某些必要条件不再满足,例如技能所需的资源耗尽,通知数据会指明是哪种条件不满足导致技能结束。
    FGameplayAbilityEndedDelegate OnGameplayAbilityEndedWithData;

    //这是一个关于技能正在被取消的通知。该通知会在 OnGameplayAbilityEnded(技能结束事件)被调用之前触发。
    //在游戏的技能系统中,技能可能会因为各种原因被取消,比如玩家主动取消技能释放、角色受到某些控制效果(如眩晕、沉默)影响而不得不中断技能等。
    //当技能开始被取消时,系统会发出这个 “技能正在被取消” 的通知。这个通知的作用在于,让开发者有机会在技能真正结束之前执行一些特定的操作,例如播放取消技能的动画、停止技能正在进行的特效、保存一些临时数据等。
    //而 OnGameplayAbilityEnded 是技能结束时触发的事件,通常用于进行技能结束后的清理工作,如释放占用的资源、更新角色状态等。
    //由于 “技能正在被取消” 是技能结束流程的一个前置阶段,所以该通知会在 OnGameplayAbilityEnded 之前被调用,以保证整个技能取消和结束的流程有序进行。
    FOnGameplayAbilityCancelled OnGameplayAbilityCancelled;
    
    //这用于技能状态任务(ability state task)处理状态结束的情况。
    //详细解释
    //在游戏开发的技能系统里,技能往往会有不同的状态,例如准备状态、激活状态、冷却状态等。技能状态任务则是负责管理和执行与技能状态相关操作的组件。
    //当某个技能状态结束时,就需要有相应的机制来处理这种状态转变。这里提到的这个机制或者功能,就是专门供技能状态任务在遇到状态结束情况时使用的。
    //它可能包含的操作有:
    //状态切换:将技能从当前结束的状态切换到下一个合适的状态,比如从激活状态结束后进入冷却状态。
    //数据清理:清除与已结束状态相关的临时数据或标记,为新状态做好准备。
    //触发事件:发送状态结束的通知,让游戏的其他部分(如界面显示、音效系统等)做出响应。
    FOnGameplayAbilityStateEnded OnGameplayAbilityStateEnded;

    //这是一个回调函数,用于处理当该技能被服务器确认的情况。
    FGenericAbilityDelegate    OnConfirmDelegate;

冷却时间相关的

    //这句话描述的是一个用于判断技能当前是否可以激活的功能。下面为你详细解释:
    //该功能会返回一个布尔值(true 或 false),用于表示当前这个技能是否能够被激活。并且,执行这个判断操作不会对游戏的状态或其他方面产生任何附带的影响,也就是所谓的 “没有副作用(Has no side effects)”。
    //技能激活条件判断
    //在游戏开发中,技能通常有一系列的激活条件,例如:
    //@资源条件:玩家可能需要消耗一定的魔法值、体力值等资源才能释放技能。如果当前资源不足,技能就不能被激活。
    //@冷却时间:为了避免玩家无限制地使用技能,技能往往有冷却时间的限制。如果技能还处于冷却状态,那么它就无法被激活。
    //@目标条件:某些技能需要有合适的目标才能释放,比如指向性技能需要玩家选中有效的目标。如果没有满足要求的目标,技能也不能激活。
    //@角色状态:玩家角色可能处于某些特殊状态,例如被眩晕、沉默等控制效果影响,此时技能也无法激活。
    //这个功能会综合考虑这些条件,判断技能在当前时刻是否满足激活的要求,并返回相应的布尔值。
  //**************非常重要的功能*********************
virtual bool CanActivateAbility(const FGameplayAbilitySpecHandle Handle, const FGameplayAbilityActorInfo* ActorInfo, const FGameplayTagContainer* SourceTags = nullptr, const FGameplayTagContainer* TargetTags = nullptr, OUT FGameplayTagContainer* OptionalRelevantTags = nullptr) const; //此函数用于判断当前技能是否能够立即被触发,并且执行该判断操作不会对游戏状态产生任何附带影响(即无副作用)。 virtual bool ShouldAbilityRespondToEvent(const FGameplayAbilityActorInfo* ActorInfo, const FGameplayEventData* Payload) const; //这个功能是用于判断某个技能是否应该被激活,并返回一个布尔值。如果判断结果为技能应该被激活,函数返回 true;反之则返回 false。 virtual bool ShouldActivateAbility(ENetRole Role) const; //该功能用于返回当前技能处于激活冷却状态时,剩余的冷却时间(以秒为单位)。 //****很重要了***** UFUNCTION(BlueprintCallable, Category = Ability) float GetCooldownTimeRemaining() const; //此函数的作用是返回当前技能处于激活冷却状态时所剩余的冷却时间,时间单位为秒。 virtual float GetCooldownTimeRemaining(const FGameplayAbilityActorInfo* ActorInfo) const; //这个功能旨在返回当前技能正在进行的冷却状态下,剩余的冷却时间(以秒为单位)以及该次冷却的原始总时长。 //这样的设计能让开发者和玩家同时了解到技能当前的冷却进度以及完整的冷却周期信息。 virtual void GetCooldownTimeRemainingAndDuration(FGameplayAbilitySpecHandle Handle, const FGameplayAbilityActorInfo* ActorInfo, float& TimeRemaining, float& CooldownDuration) const; //这个功能是用于返回所有能够使某个GA进入冷却状态的标签(Tags) virtual const FGameplayTagContainer* GetCooldownTags() const; //这个功能主要用于判断一个技能(能力,Ability)是否可以激活。它会检查技能的标签(Tags)情况,当满足以下三个条件时返回 true,否则返回 false: //这个功能主要用于判断一个技能(能力,Ability)是否可以激活。它会检查技能的标签(Tags)情况,当满足以下三个条件时返回 true,否则返回 false: //技能的所有标签都未被阻止(即没有被游戏机制禁止使用)。 //技能本身不带有 “Blocking” 标签。 //技能拥有所有 “Required” 标签。 virtual bool DoesAbilitySatisfyTagRequirements(const UAbilitySystemComponent& AbilitySystemComponent, const FGameplayTagContainer* SourceTags = nullptr, const FGameplayTagContainer* TargetTags = nullptr, OUT FGameplayTagContainer* OptionalRelevantTags = nullptr) const; //这个功能用于判断当前GA(能力,Ability)是否正在阻止其他技能的使用。 virtual bool IsBlockingOtherAbilities() const; //此功能用于设置GA(能力,Ability)的阻塞标志(block flags)是启用还是禁用。不过,该设置仅对已实例化的技能有效。 UFUNCTION(BlueprintCallable, Category = Ability) virtual void SetShouldBlockOtherAbilities(bool bShouldBlockAbilities);

取消技能相关的

    //销毁每次执行时实例化的能力。每个角色实例化的能力应该“重置”。任何处于激活状态的能力状态任务都会收到“能力状态中断”事件。对于非实例化能力 - 我们能做些什么呢? 
    virtual void CancelAbility(const FGameplayAbilitySpecHandle Handle, const FGameplayAbilityActorInfo* ActorInfo, const FGameplayAbilityActivationInfo ActivationInfo, bool bReplicateCancelAbility);

    //从蓝图中调用,以正常取消该技能。
    UFUNCTION(BlueprintCallable, Category = Ability, DisplayName = "CancelAbility", meta=(ScriptName = "CancelAbility"))
    void K2_CancelAbility();

    //如果此技能可以被取消,则返回 true。
    virtual bool CanBeCanceled() const;

    //设置该技能是否应忽略取消请求。此设置仅对实例化技能有效。
    UFUNCTION(BlueprintCallable, Category=Ability)
    virtual void SetCanBeCanceled(bool bCanBeCanceled);

Commit Ability

commit应该是5.3大改以后的东西 没玩明白

    //尝试提交技能(消耗资源等)。这是我们最后一次允许技能激活失败的机会。重写了 `ActivateAbility` 方法的子类必须自行调用此方法!
    //ue5.3以后就变成了commit    UFUNCTION(BlueprintCallable, Category = Ability, DisplayName = "CommitAbility", meta=(ScriptName = "CommitAbility"))
    virtual bool K2_CommitAbility();

    //仅尝试触发技能的冷却机制。若 “BroadcastCommitEvent(广播技能激活事件)” 参数设为 “true”,
    //则会广播激活事件,诸如 “WaitAbilityCommit(等待技能激活)” 这类任务会监听此事件。
    UFUNCTION(BlueprintCallable, Category = Ability, DisplayName = "CommitAbilityCooldown", meta=(ScriptName = "CommitAbilityCooldown"))
    virtual bool K2_CommitAbilityCooldown(bool BroadcastCommitEvent=false, bool ForceCooldown=false);

    //仅尝试消耗该技能的使用成本(如消耗魔法值、资源等)。如果 “BroadcastCommitEvent”(广播技能激活事件)参数为 “true”,
    //则会广播技能激活事件,像 “WaitAbilityCommit”(等待技能激活)这类任务会监听此事件。
    UFUNCTION(BlueprintCallable, Category = Ability, DisplayName = "CommitAbilityCost", meta=(ScriptName = "CommitAbilityCost"))
    virtual bool K2_CommitAbilityCost(bool BroadcastCommitEvent=false);

    //检查技能的冷却时间,但不应用该冷却(即不会触发技能进入冷却状态)。 
    UFUNCTION(BlueprintCallable, Category = Ability, DisplayName = "CheckAbilityCooldown", meta=(ScriptName = "CheckAbilityCooldown"))
    virtual bool K2_CheckAbilityCooldown();

    //检查该技能的使用成本(如魔法值、体力、特殊资源等),但不进行实际消耗。 
    UFUNCTION(BlueprintCallable, Category = Ability, DisplayName = "CheckAbilityCost", meta=(ScriptName = "CheckAbilityCost"))
    virtual bool K2_CheckAbilityCost();

    //几个虚函数
    virtual bool CommitAbility(const FGameplayAbilitySpecHandle Handle, const FGameplayAbilityActorInfo* ActorInfo, const FGameplayAbilityActivationInfo ActivationInfo, OUT FGameplayTagContainer* OptionalRelevantTags = nullptr);
    virtual bool CommitAbilityCooldown(const FGameplayAbilitySpecHandle Handle, const FGameplayAbilityActorInfo* ActorInfo, const FGameplayAbilityActivationInfo ActivationInfo, const bool ForceCooldown, OUT FGameplayTagContainer* OptionalRelevantTags = nullptr);
    virtual bool CommitAbilityCost(const FGameplayAbilitySpecHandle Handle, const FGameplayAbilityActorInfo* ActorInfo, const FGameplayAbilityActivationInfo ActivationInfo, OUT FGameplayTagContainer* OptionalRelevantTags = nullptr);

    //这是在提交技能(如消耗资源等操作)之前允许技能激活失败的最后机会,此检查通常与 `CanActivateAbility`(能否激活技能)的检查相同。
    //不过,有些技能如果在 `CommitExecute`(提交执行)阶段会消耗额外的资源或满足额外条件,可能需要在此处进行额外的检查。 
    virtual bool CommitCheck(const FGameplayAbilitySpecHandle Handle, const FGameplayAbilityActorInfo* ActorInfo, const FGameplayAbilityActivationInfo ActivationInfo, OUT FGameplayTagContainer* OptionalRelevantTags = nullptr);

    //从 CommitAbility(提交技能)调用的蓝图(Blueprint,简称 BP)事件。
    //在游戏开发里,CommitAbility 通常是技能系统里用于确认技能激活、消耗资源并触发技能效果的函数。
    //当调用这个函数时,可能会触发一个蓝图事件,开发者能在蓝图可视化编辑环境里对该事件进行响应,编写自定义逻辑,像播放动画、生成特效、处理伤害计算等操作。
    UFUNCTION(BlueprintImplementableEvent, Category = Ability, DisplayName = "CommitExecute", meta = (ScriptName = "CommitExecute"))
    void K2_CommitExecute();

    //以原子操作的方式执行提交操作(消耗资源、启动冷却时间等)。
    virtual void CommitExecute(const FGameplayAbilitySpecHandle Handle, const FGameplayAbilityActorInfo* ActorInfo, const FGameplayAbilityActivationInfo ActivationInfo);

    //返回用于确定冷却时间的GE效果。
    virtual UGameplayEffect* GetCooldownGameplayEffect() const;

    //返回用于应用GA COST的GE。
    virtual UGameplayEffect* GetCostGameplayEffect() const;

    //检查技能的冷却状态。如果技能可以再次使用,则返回 `true`;反之则返回 `false`。 
    virtual bool CheckCooldown(const FGameplayAbilitySpecHandle Handle, const FGameplayAbilityActorInfo* ActorInfo, OUT FGameplayTagContainer* OptionalRelevantTags = nullptr) const;

    //将冷却时间游戏玩法效果应用到目标上。
    //在游戏开发的技能系统中,“CooldownGameplayEffect” 一般是指用来实现技能冷却机制的一种游戏玩法效果,这种效果可能包含了冷却时间的具体数值、冷却时间的起始和结束逻辑等。
    //当调用此操作时,意味着会让目标(通常是技能的使用者)进入该技能的冷却状态,开始计算冷却时间,在冷却时间内该技能无法再次使用。
    virtual void ApplyCooldown(const FGameplayAbilitySpecHandle Handle, const FGameplayAbilityActorInfo* ActorInfo, const FGameplayAbilityActivationInfo ActivationInfo) const;

    //检查COST。如果有足够资源来使用该技能,则返回 `true`;反之则返回 `false`。
    //**********很重要
    virtual bool CheckCost(const FGameplayAbilitySpecHandle Handle, const FGameplayAbilityActorInfo* ActorInfo, OUT FGameplayTagContainer* OptionalRelevantTags = nullptr) const;

    //将该技能的COST施加到目标上。
    virtual void ApplyCost(const FGameplayAbilitySpecHandle Handle, const FGameplayAbilityActorInfo* ActorInfo, const FGameplayAbilityActivationInfo ActivationInfo) const;

输入相关的GA 感觉似乎是接管了InputSystem和enhancedinputsystem

    //输入绑定存根
    virtual void InputPressed(const FGameplayAbilitySpecHandle Handle, const FGameplayAbilityActorInfo* ActorInfo, const FGameplayAbilityActivationInfo ActivationInfo) {};

    //输入绑定存根
    virtual void InputReleased(const FGameplayAbilitySpecHandle Handle, const FGameplayAbilityActorInfo* ActorInfo, const FGameplayAbilityActivationInfo ActivationInfo) {};

    //从 AbilityTask_WaitConfirmCancel(等待确认或取消的技能任务)调用此函数,以处理输入确认操作。
    virtual void OnWaitingForConfirmInputBegin() {}
    virtual void OnWaitingForConfirmInputEnd() {}
    

动画

    //返回该技能当前正在播放的蒙太奇(Montage),如果有的话。
    UFUNCTION(BlueprintCallable, Category = Animation)
    UAnimMontage* GetCurrentMontage() const;

    //此调用用于从蒙太奇任务中设置或获取当前的蒙太奇。进行设置是为了将蒙太奇事件与技能事件关联起来。
    virtual void SetCurrentMontage(class UAnimMontage* InCurrentMontage);

获取level和source    

//返回该技能的当前等级。   

//在游戏的技能系统中,技能通常会有不同的等级,等级的提升可能会带来技能效果的增强,比如更高的伤害、更长的持续时间、更短的冷却时间等。

//这个函数的作用就是获取该技能目前所处的等级,开发者可以根据这个等级来决定技能在不同阶段的具体表现和参数。
    UFUNCTION(BlueprintCallable, Category = Ability)
    int32 GetAbilityLevel() const;

    //返回非实例化技能的当前技能等级。在这些情况下,你必须调用此版本的函数!
    int32 GetAbilityLevel(FGameplayAbilitySpecHandle Handle, const FGameplayAbilityActorInfo* ActorInfo) const;
//这个功能是专门针对非实例化技能(abilities)设计的,用于返回当前技能的等级。同时,在处理非实例化技能的相关情境下,必须调用此版本的函数来获取技能等级。 UFUNCTION(BlueprintCallable, Category = Ability, meta = (DisplayName = "GetAbilityLevelNonInstanced", ReturnDisplayName = "AbilityLevel")) int32 GetAbilityLevel_BP(FGameplayAbilitySpecHandle Handle, const FGameplayAbilityActorInfo& ActorInfo) const; //这个功能用于获取与当前GA(能力,Ability)相关联的源对象(SourceObject)。不过,该操作只能在已实例化的技能上执行。 UFUNCTION(BlueprintCallable, Category = Ability) UObject* GetCurrentSourceObject() const; //此功能用于获取与当前技能(能力,Ability)相关联的源对象(SourceObject),并且该操作可在非实例化技能上调用。 UObject* GetSourceObject(FGameplayAbilitySpecHandle Handle, const FGameplayAbilityActorInfo* ActorInfo) const; //此功能允许从一个非实例化的技能(能力,Ability)中获取与之关联的源对象(SourceObject)。 //在游戏开发的技能系统里,源对象通常代表技能效果的发起者或者根源, //获取它有助于在不同情境下处理技能相关的逻辑,即便该技能并非以实例化形式存在。 UFUNCTION(BlueprintCallable, Category = Ability, meta = (DisplayName = "GetSourceObjectNonInstanced", ReturnDisplayName = "SourceObject")) UObject* GetSourceObject_BP(FGameplayAbilitySpecHandle Handle, const FGameplayAbilityActorInfo& ActorInfo) const;

和ASC交互

    //这是一个由技能系统组件(Ability System Component)调用的函数,其作用是通知当前技能实例(ability instance),
    //与之对应的远程实例已经结束。在多人游戏或者分布式游戏系统中,技能可能会在本地和远程的不同客户端或服务器实例上同时运行,
    //当远程的技能实例结束时,需要有一种机制来通知本地的对应实例,以便本地实例做出相应的处理
    virtual void SetRemoteInstanceHasEnded();

    //这个功能是一个回调通知机制,当技能(能力,Ability)所关联的化身角色(AvatarActor)被替换时,
    //系统会调用此函数告知该技能。若技能的运行依赖于化身角色的状态,那么在接收到此通知后,技能可能会选择自行结束。
    virtual void NotifyAvatarDestroyed();
//此功能是一个回调机制,当技能中的某个任务需要等待玩家执行特定操作时,系统会调用该函数来通知技能。 //这使得技能能够知晓当前存在等待玩家交互的情况,并可以根据这一情况做出相应的处理。这是用于abilityTask的 virtual void NotifyAbilityTaskWaitingOnPlayerData(class UAbilityTask* AbilityTask); //这是一个回调函数,当技能中的某个任务需要等待玩家操控的化身角色(在游戏世界里通常代表玩家本人的角色实体)完成特定动作或达到特定状态时, //系统会调用此函数来通知该技能。通过这种机制,技能能够感知到任务的等待状态,并根据情况做出相应的响应和处理。 virtual void NotifyAbilityTaskWaitingOnAvatar(class UAbilityTask* AbilityTask); //这是一个回调函数,当一个技能(能力,Ability)被赋予给技能系统组件(AbilitySystemComponent)时会触发该函数调用。 //技能系统组件通常负责管理和执行角色所拥有的各种技能,而这个回调函数允许开发者在技能被添加到组件时执行特定的初始化或其他逻辑操作。 virtual void OnGiveAbility(const FGameplayAbilityActorInfo* ActorInfo, const FGameplayAbilitySpec& Spec); //这是一个回调函数,当一个技能(能力,Ability)被赋予给技能系统组件(AbilitySystemComponent)时会触发该函数调用。 //技能系统组件通常负责管理和执行角色所拥有的各种技能,而这个回调函数允许开发者在技能被添加到组件时执行特定的初始化或其他逻辑操作。 virtual void OnRemoveAbility(const FGameplayAbilityActorInfo* ActorInfo, const FGameplayAbilitySpec& Spec) {} //这是一个回调函数,当技能(能力,Ability)所关联的化身角色(Avatar Actor)被设置或者发生改变时,该函数会被调用。 //化身角色通常代表玩家操控的角色或者游戏中的智能体,技能与化身角色紧密相连,角色的变化可能会影响技能的运行和表现,所以需要在角色改变时进行相应的处理。 virtual void OnAvatarSet(const FGameplayAbilityActorInfo* ActorInfo, const FGameplayAbilitySpec& Spec); //这个功能的核心是接收一个技能(能力)规格(Ability Spec),并检查是否应该允许该技能规格进行复制。 //需要注意的是,这里的复制限制仅针对 UAbilitySystemComponent 中可激活技能列表(ActivatableAbilities)里的技能规格,而不是技能的 UObject 本身。 //在多人游戏开发中,技能规格的复制是确保不同客户端和服务器之间技能状态同步的重要机制,但有时我们可能需要根据特定条件来控制某些技能规格是否进行复制。 virtual bool ShouldReplicateAbilitySpec(const FGameplayAbilitySpec& AbilitySpec) const { return true; } //此功能的作用是使当前的预测键(Prediction Key)失效。 //在多人游戏的网络同步机制里,预测键是一个重要的概念,用于客户端预测服务器端的行为,以减少玩家操作的延迟感。 //但在某些特定情况下,服务器会执行只有它能进行的逻辑,执行完这些逻辑后又会进行一个客户端原本可以预测的操作。 //此时就需要调用这个功能来使当前预测键失效,该操作会立即返回,并且除了清除当前预测键之外没有其他副作用。 UFUNCTION(BlueprintCallable, Category = Ability) void InvalidateClientPredictionKey() const; //这个功能的作用是移除赋予当前技能(能力)的游戏效果(GameplayEffect),不过此操作仅允许在已实例化的技能上执行。 //在游戏开发里,技能往往可以通过游戏效果来赋予角色,例如某个增益效果可能会临时让角色获得一个新技能。 //当不再需要这个技能时,就可以使用该功能移除赋予此技能的游戏效果。 UFUNCTION(BlueprintCallable, Category = Ability) virtual void RemoveGrantedByEffect(); //这个功能的主要目的是向用户添加并显示一条调试消息。在游戏开发或者其他应用程序开发过程中,调试消息是一种非常有用的工具, //它可以帮助开发者在程序运行时向用户展示一些关键信息,比如技能的状态、系统的错误提示、性能数据等,方便开发者和用户及时了解程序的运行情况,排查潜在问题。 void AddAbilityTaskDebugMessage(UGameplayTask* AbilityTask, FString DebugMessage);

没什么大用的部分就不解释了

    // --------------------------------------
    //    Public variables, exposed for backwards compatibility
    // --------------------------------------
公共变量,为了向后兼容

override掉一些Uobj

 1     virtual UWorld* GetWorld() const override;
 2     virtual int32 GetFunctionCallspace(UFunction* Function, FFrame* Stack) override;
 3     virtual bool CallRemoteFunction(UFunction* Function, void* Parameters, FOutParmRec* OutParms, FFrame* Stack) override;
 4     virtual bool IsSupportedForNetworking() const override;
 5 
 6 #if WITH_EDITOR
 7     virtual EDataValidationResult IsDataValid(FDataValidationContext& Context) const override;
 8 #endif
 9 
10     /** Overridden to allow Blueprint replicated properties to work */
11     //对其进行重写是为了让蓝图(Blueprint)的可复制属性能够正常工作。
12     virtual void GetLifetimeReplicatedProps(TArray< class FLifetimeProperty >& OutLifetimeProps) const;
13 
14 #if UE_WITH_IRIS
15     /** Register all replication fragments */
16     //注册所有的复制片段。
17     virtual void RegisterReplicationFragments(UE::Net::FFragmentRegistrationContext& Context, UE::Net::EFragmentRegistrationFlags RegistrationFlags) override;
18 #endif // UE_WITH_IRIS
UObject overrides

TaskOwnner的一些Interface

    // --------------------------------------
    //    IGameplayTaskOwnerInterface
    // --------------------------------------    
virtual UGameplayTasksComponent* GetGameplayTasksComponent(const UGameplayTask& Task) const override; virtual AActor* GetGameplayTaskOwner(const UGameplayTask* Task) const override; virtual AActor* GetGameplayTaskAvatar(const UGameplayTask* Task) const override; virtual void OnGameplayTaskInitialized(UGameplayTask& Task) override; virtual void OnGameplayTaskActivated(UGameplayTask& Task) override; virtual void OnGameplayTaskDeactivated(UGameplayTask& Task) override;

 

protected:
     /**
      * 允许派生类设置此技能被视为具有的默认游戏玩法标签(以前称为技能标签)。
      * 此操作只能在构造过程中调用。
      * 在运行时,通过游戏玩法技能的默认对象类(CDO)查询技能规范(AbilitySpec),以获取其技能标签,这些标签可能是这些资产标签与专门授予的动态技能标签的组合
      * (预计从技能规范生成的所有实例都共享相同的技能标签)。
      */ 
    void SetAssetTags(const FGameplayTagContainer& InAbilityTags);

Ability对event的回复

    //如果该技能目前可以激活,则返回 true。此操作没有副作用。
    UFUNCTION(BlueprintImplementableEvent, Category = Ability, DisplayName = "ShouldAbilityRespondToEvent", meta=(ScriptName = "ShouldAbilityRespondToEvent"))
    bool K2_ShouldAbilityRespondToEvent(FGameplayAbilityActorInfo ActorInfo, FGameplayEventData Payload) const;

    bool bHasBlueprintShouldAbilityRespondToEvent;

    //发送一个游戏玩法事件,同时创建一个预测窗口。
    //结合起来的作用
    //发送游戏玩法事件的同时创建预测窗口,意味着在触发某个游戏事件时,开启一个时间段来进行客户端的预测处理。
    //例如,当玩家释放技能时,客户端会立即发送技能释放的游戏玩法事件,并创建预测窗口,在窗口时间内本地模拟技能的效果(如动画播放、伤害计算等),
    //等待服务器的确认信息,以确保游戏状态在客户端和服务器之间的最终一致性。
    UFUNCTION(BlueprintCallable, Category = Ability)
    virtual void SendGameplayEvent(UPARAM(meta=(GameplayTagFilter="GameplayEventTagsCategory")) FGameplayTag EventTag, FGameplayEventData Payload);

是否可以激活当前GA

    //如果该技能目前可以激活,则返回 true,且此操作不会产生任何副作用。
    UFUNCTION(BlueprintImplementableEvent, Category = Ability, DisplayName="CanActivateAbility", meta=(ScriptName="CanActivateAbility"))
    bool K2_CanActivateAbility(FGameplayAbilityActorInfo ActorInfo, const FGameplayAbilitySpecHandle Handle, FGameplayTagContainer& RelevantTags) const;

    bool bHasBlueprintCanUse;

激活GA

    /**
     * 该函数是定义技能具体功能的主要函数。
     *  - 子类通常需要重写此函数
     *  - 此函数图表(蓝图中可理解为节点图)应调用“提交技能(CommitAbility)”函数
     *  - 此函数图表应调用“结束技能(EndAbility)”函数
     *
     *  此函数图表中允许使用延迟/异步操作。需要注意的是,“提交技能”和“结束技能”的调用要求是针对“K2_ActivateAbility”函数图表而言的。
     *  在 C++ 代码中,调用“K2_ActivateAbility()”函数时,可能在未调用“提交技能”或“结束技能”函数的情况下就返回了。
     *  但这通常只发生在存在延迟/异步操作未完成时。当“K2_ActivateAbility”逻辑上执行完毕后,我们期望“提交技能”和“结束技能”函数已经被调用。
     */
    //激活GA
    UFUNCTION(BlueprintImplementableEvent, Category = Ability, DisplayName = "ActivateAbility", meta=(ScriptName = "ActivateAbility"))
    void K2_ActivateAbility();

    UFUNCTION(BlueprintImplementableEvent, Category = Ability, DisplayName = "ActivateAbilityFromEvent", meta=(ScriptName = "ActivateAbilityFromEvent"))
    void K2_ActivateAbilityFromEvent(const FGameplayEventData& EventData);

    bool bHasBlueprintActivate;
    bool bHasBlueprintActivateFromEvent;

    //实际激活技能,但请勿直接调用此方法。
    virtual void ActivateAbility(const FGameplayAbilitySpecHandle Handle, const FGameplayAbilityActorInfo* ActorInfo, const FGameplayAbilityActivationInfo ActivationInfo, const FGameplayEventData* TriggerEventData);

    //执行一些常规的初始化操作,然后调用 ActivateAbility 函数。
    virtual void PreActivate(const FGameplayAbilitySpecHandle Handle, const FGameplayAbilityActorInfo* ActorInfo, const FGameplayAbilityActivationInfo ActivationInfo, FOnGameplayAbilityEnded::FDelegate* OnGameplayAbilityEndedDelegate, const FGameplayEventData* TriggerEventData = nullptr);

    //执行 PreActivate 和 ActivateAbility 方法。
    void CallActivateAbility(const FGameplayAbilitySpecHandle Handle, const FGameplayAbilityActorInfo* ActorInfo, const FGameplayAbilityActivationInfo ActivationInfo, FOnGameplayAbilityEnded::FDelegate* OnGameplayAbilityEndedDelegate = nullptr, const FGameplayEventData* TriggerEventData = nullptr);

    //当服务器确认预测性技能的执行时,会调用此方法。
    virtual void ConfirmActivateSucceed();

结束GA

    //可从蓝图中调用此操作,以在不取消技能的情况下强制结束该技能。
    //这会将技能结束的信息复制到客户端或服务器,此操作可能会中断正在进行的任务。
    UFUNCTION(BlueprintCallable, Category = Ability, DisplayName="End Ability", meta=(ScriptName = "EndAbility"))
    virtual void K2_EndAbility();

    //可以从蓝图中调用此操作,让技能自然结束。这只会在本地结束预测性技能,使技能在客户端或服务器上自然终止。
    UFUNCTION(BlueprintCallable, Category = Ability, DisplayName = "End Ability Locally", meta = (ScriptName = "EndAbilityLocally"))
    virtual void K2_EndAbilityLocally();

    //这是一个蓝图事件,当技能正常结束或异常结束时都会调用该事件。
    UFUNCTION(BlueprintImplementableEvent, Category = Ability, DisplayName = "OnEndAbility", meta=(ScriptName = "OnEndAbility"))
    void K2_OnEndAbility(bool bWasCancelled);

    //检查该技能是否可以结束。
    bool IsEndAbilityValid(const FGameplayAbilitySpecHandle Handle, const FGameplayAbilityActorInfo* ActorInfo) const;

    //这是一个原生函数(通常指用 C++ 等编程语言实现的底层函数),当技能正常结束或异常结束时会调用该函数。
    //如果 bReplicate(可能是一个布尔类型的标志变量)被设置为 true,则尝试将技能结束的信息复制到客户端或服务器。
    virtual void EndAbility(const FGameplayAbilitySpecHandle Handle, const FGameplayAbilityActorInfo* ActorInfo, const FGameplayAbilityActivationInfo ActivationInfo, bool bReplicateEndAbility, bool bWasCancelled);

对目标应用GE非常重要

    //向目标应用GE
    UFUNCTION(BlueprintCallable, Category = Ability, DisplayName = "ApplyGameplayEffectToTarget", meta=(ScriptName = "ApplyGameplayEffectToTarget"))
    TArray<FActiveGameplayEffectHandle> BP_ApplyGameplayEffectToTarget(FGameplayAbilityTargetDataHandle TargetData, TSubclassOf<UGameplayEffect> GameplayEffectClass, int32 GameplayEffectLevel = 1, int32 Stacks = 1);

    //此方法不可在蓝图中调用,在类默认对象(CDO)或非实例化的游戏玩法技能上调用是安全的。
    TArray<FActiveGameplayEffectHandle> ApplyGameplayEffectToTarget(const FGameplayAbilitySpecHandle Handle, const FGameplayAbilityActorInfo* ActorInfo, const FGameplayAbilityActivationInfo ActivationInfo, const FGameplayAbilityTargetDataHandle& Target, TSubclassOf<UGameplayEffect> GameplayEffectClass, float GameplayEffectLevel, int32 Stacks = 1) const;

    //将之前创建好的游戏玩法效果规格应用到一个目标上。
    //游戏玩法效果规格(Gameplay Effect Spec):在虚幻引擎的游戏玩法能力系统(Gameplay Ability System,GAS)中,
    //Gameplay Effect 用于定义各种游戏效果,如属性修改(增加生命值、提升攻击力)、状态施加(眩晕、中毒)等。
    //而 Gameplay Effect Spec(FGameplayEffectSpec)是对 Gameplay Effect 进行实例化和参数化后的对象,它包含了具体应用效果时所需的详细信息,像效果的等级、目标、修正值等。
    UFUNCTION(BlueprintCallable, Category = Ability, DisplayName = "ApplyGameplayEffectSpecToTarget", meta=(ScriptName = "ApplyGameplayEffectSpecToTarget"))
    TArray<FActiveGameplayEffectHandle> K2_ApplyGameplayEffectSpecToTarget(const FGameplayEffectSpecHandle EffectSpecHandle, FGameplayAbilityTargetDataHandle TargetData);

    TArray<FActiveGameplayEffectHandle> ApplyGameplayEffectSpecToTarget(const FGameplayAbilitySpecHandle AbilityHandle, const FGameplayAbilityActorInfo* ActorInfo, const FGameplayAbilityActivationInfo ActivationInfo, const FGameplayEffectSpecHandle SpecHandle, const FGameplayAbilityTargetDataHandle& TargetData) const;

对自身移除GE

    //这句话描述的功能是从技能的拥有者身上移除那些与给定的资产等级标签(Asset Level Tags)相匹配的游戏玩法效果(Gameplay Effects)。
    UFUNCTION(BlueprintCallable, Category = Ability, DisplayName="RemoveGameplayEffectFromOwnerWithAssetTags", meta=(ScriptName="RemoveGameplayEffectFromOwnerWithAssetTags"))
    void BP_RemoveGameplayEffectFromOwnerWithAssetTags(FGameplayTagContainer WithAssetTags, int32 StacksToRemove = -1);

    //此功能是从技能拥有者身上移除那些能够授予指定标签的游戏玩法效果(Gameplay Effects)。在虚幻引擎的游戏玩法能力系统(Gameplay Ability System,GAS)里,
    //游戏玩法效果可附带标签,这些标签能用来表示特定的状态、属性或能力等。该操作会检查技能拥有者当前身上所有的游戏玩法效果,找出那些会授予给定标签的效果并将其移除。
    UFUNCTION(BlueprintCallable, Category = Ability, DisplayName="RemoveGameplayEffectFromOwnerWithGrantedTags", meta=(ScriptName="RemoveGameplayEffectFromOwnerWithGrantedTags"))
    void BP_RemoveGameplayEffectFromOwnerWithGrantedTags(FGameplayTagContainer WithGrantedTags, int32 StacksToRemove = -1);

    //该功能是从技能的拥有者身上移除与给定句柄(Handle)相匹配的游戏玩法效果(GameplayEffect)。
    //在虚幻引擎的游戏玩法能力系统(Gameplay Ability System,GAS)中,当一个 GameplayEffect 被应用到某个对象上时,系统会为其分配一个唯一的句柄,
    //通过这个句柄可以对该效果进行管理和操作,此操作就是利用句柄来精准移除特定的 GameplayEffect。
    UFUNCTION(BlueprintCallable, Category = Ability, DisplayName = "RemoveGameplayEffectFromOwnerWithHandle", meta=(ScriptName = "RemoveGameplayEffectFromOwnerWithHandle"))
    void BP_RemoveGameplayEffectFromOwnerWithHandle(FActiveGameplayEffectHandle Handle, int32 StacksToRemove = -1);

GameCue,GA可以直接调用CUE而不需要GE

    //指的是在技能所有者(通常是角色)上触发一个游戏玩法提示(gameplay cue)。
    UFUNCTION(BlueprintCallable, Category = Ability, meta=(GameplayTagFilter="GameplayCue"), DisplayName="Execute GameplayCue On Owner", meta=(ScriptName="ExecuteGameplayCue"))
    virtual void K2_ExecuteGameplayCue(FGameplayTag GameplayCueTag, FGameplayEffectContextHandle Context);

    //在技能所有者上触发一个游戏玩法提示(gameplay cue),并且同时传递额外的参数。
    UFUNCTION(BlueprintCallable, Category = Ability, meta = (GameplayTagFilter = "GameplayCue"), DisplayName = "Execute GameplayCueWithParams On Owner", meta=(ScriptName = "ExecuteGameplayCueWithParams"))
    virtual void K2_ExecuteGameplayCueWithParams(FGameplayTag GameplayCueTag, const FGameplayCueParameters& GameplayCueParameters);

    //该功能用于给技能的所有者添加一个持续的游戏玩法提示(Persistent Gameplay Cue)。并且可以选择在技能结束时移除这个提示。
    UFUNCTION(BlueprintCallable, Category = Ability, meta=(GameplayTagFilter="GameplayCue"), DisplayName="Add GameplayCue To Owner", meta=(ScriptName="AddGameplayCue"))
    virtual void K2_AddGameplayCue(FGameplayTag GameplayCueTag, FGameplayEffectContextHandle Context, bool bRemoveOnAbilityEnd = true);

    //该功能用于给技能的所有者添加一个持续的游戏玩法提示(Persistent Gameplay Cue)。并且可以选择在技能结束时移除这个提示。
    UFUNCTION(BlueprintCallable, Category = Ability, meta = (GameplayTagFilter = "GameplayCue"), DisplayName = "Add GameplayCueWithParams To Owner", meta=(ScriptName = "AddGameplayCueWithParams"))
    virtual void K2_AddGameplayCueWithParams(FGameplayTag GameplayCueTag, const FGameplayCueParameters& GameplayCueParameter, bool bRemoveOnAbilityEnd = true);

    //此功能的目的是从技能的所有者(通常是游戏角色或实体)身上移除一个持续的游戏玩法提示(Persistent Gameplay Cue)。
    UFUNCTION(BlueprintCallable, Category = Ability, meta=(GameplayTagFilter="GameplayCue"), DisplayName="Remove GameplayCue From Owner", meta=(ScriptName="RemoveGameplayCue"))
    virtual void K2_RemoveGameplayCue(FGameplayTag GameplayCueTag);

中间略过若干没事干别动的东西

Ability Tasks
    //此功能用于查找所有当前处于活动状态且名称为 InstanceName 的任务,然后对这些任务进行确认操作。
    //不过,“确认” 这个操作具体意味着什么,会因每个任务的不同而有所差异。默认情况下,如果 bEndTask 参数为 true,则该功能除了结束任务之外,不会执行其他额外的操作。
    UFUNCTION(BlueprintCallable, Category = Ability)
    void ConfirmTaskByInstanceName(FName InstanceName, bool bEndTask);

    //这是一个内部函数,其主要作用是取消上一帧中通过实例名称指定要取消的所有任务。在游戏或复杂程序运行过程中,任务管理是一个重要的环节,有时候需要根据特定条件或用户操作来取消某些任务。
    //这个函数就是为了处理这种需求,它会按照之前记录的要取消的任务的实例名称,在当前操作中把这些任务取消掉。
    void EndOrCancelTasksByInstanceName();
    TArray<FName> CancelTaskInstanceNames;

    //此功能的作用是将所有具有指定实例名称的任务添加到一个列表中,这些任务会在下一帧被结束(而不是取消)。同时还提到可以参考 CancelTaskByInstanceName 函数,
    //这表明二者可能在任务管理方面存在关联,但处理方式有所不同。在游戏开发或者复杂程序运行中,任务管理是一个关键环节,合理地结束或取消任务对于系统的稳定性和性能优化至关重要。
    UFUNCTION(BlueprintCallable, Category = Ability)
    void EndTaskByInstanceName(FName InstanceName);
    TArray<FName> EndTaskInstanceNames;

    //此功能主要用于管理游戏或程序中的任务。它会把所有具有指定实例名称的任务添加到一个列表里,这些任务会在下一帧被取消(而非结束)。
    //同时还提及可参考 EndTaskByInstanceName 函数,意味着这两个函数在任务管理方面有不同的作用,分别负责任务的取消和结束操作。
    UFUNCTION(BlueprintCallable, Category = Ability)
    void CancelTaskByInstanceName(FName InstanceName);

    //这个功能的作用是结束具有指定名称的所有正在活跃的技能状态任务。若指定的名称为 “None”,则会以任意顺序结束所有活跃的技能状态任务。
    //在游戏开发里,技能状态任务通常是一些持续性的操作,比如技能的持续伤害效果、技能的增益状态等。结束这些任务意味着停止它们的运行,并进行必要的清理工作。
    UFUNCTION(BlueprintCallable, Category = Ability)
    void EndAbilityState(FName OptionalStateNameToEnd);

    //这里提到的是一个当前活跃任务的列表,并且明确提示不要直接对其进行修改。
    //在游戏开发或其他复杂的程序系统中,任务管理是很重要的一部分,这个列表记录了当前正在运行的任务。
    //之所以不建议直接修改,是为了保证系统的稳定性和数据的一致性,避免因不当修改引发各种问题。
    UPROPERTY()
    TArray<TObjectPtr<UGameplayTask>>    ActiveTasks;

    //在软件开发尤其是游戏开发的技能系统里,任务(Tasks)在其整个生命周期内能够发出调试信息,这些信息的主要用途是辅助开发者进行调试工作。
    //并且,这些调试信息会被保存到技能(Ability)中,从而保证在任务结束之后,这些信息依然能够被保留下来,方便开发者后续查看和分析。
    TArray<FAbilityTaskDebugMessage> TaskDebugMessages;

动画相关的GA

    //该功能的作用是立即将正在播放的蒙太奇(Montage)跳转到指定的片段(Section)。
    UFUNCTION(BlueprintCallable, Category="Ability|Animation")
    void MontageJumpToSection(FName SectionName);

    //“Sets pending section on active montage” 指的是在当前正在播放的动画蒙太奇(Animation Montage)里设置一个待执行的片段(Section)。
    UFUNCTION(BlueprintCallable, Category = "Ability|Animation")
    void MontageSetNextSectionName(FName FromSectionName, FName ToSectionName);

    /**
     *停止当前正在播放的蒙太奇
     * @param OverrideBlendTime If >= 0, will override the BlendOutTime parameter on the AnimMontage instance
     */
    UFUNCTION(BlueprintCallable, Category="Ability|Animation", Meta = (AdvancedDisplay = "OverrideBlendOutTime"))
    void MontageStop(float OverrideBlendOutTime = -1.0f);

    //描述的是由当前技能(ability)正在播放的活动动画蒙太奇(active montage)。
    UPROPERTY()
    TObjectPtr<class UAnimMontage> CurrentMontage;

目标数据

    //这句话描述的功能是基于技能所有者的化身(avatar,通常指游戏中代表玩家或角色的形象)当前所处的位置来创建一个目标位置。
    UFUNCTION(BlueprintPure, Category = Ability)
    FGameplayAbilityTargetingLocationInfo MakeTargetLocationInfoFromOwnerActor();

    //此功能是从技能所有者化身的骨骼网格体(skeletal mesh)上的一个套接字(socket)来创建目标位置。
    UFUNCTION(BlueprintPure, Category = Ability)
    FGameplayAbilityTargetingLocationInfo MakeTargetLocationInfoFromOwnerSkeletalMeshComponent(FName SocketName);

这个看不懂不知道哪里用

对于临时信息的setter应用时应该碰不到

 

剩下的都是一堆设置信息 没事干别碰

    //当前角色
    mutable const FGameplayAbilityActorInfo* CurrentActorInfo;

    /** For instanced abilities */
    //对于实例化技能  实例化技能只能通过当前句柄
    mutable FGameplayAbilitySpecHandle CurrentSpecHandle;

    /** GameplayCues that were added during this ability that will get automatically removed when it ends */
    //在该技能使用期间添加的游戏玩法提示(Gameplay Cues),会在技能结束时自动移除。
    TSet<FGameplayTag> TrackedGameplayCues;

    /** True if the ability is currently active. For instance per owner abilities */
    //如果该技能当前处于激活状态,则返回 true。这适用于每个所有者(通常指技能使用者,如游戏角色)的技能情况。
    UPROPERTY()
    bool bIsActive;
    
    /** True if the end ability has been called, but has not yet completed. */
    //如果已经调用了结束技能的操作,但技能尚未完成结束流程,则返回 true。
    UPROPERTY()
    bool bIsAbilityEnding = false;

    /** True if the ability is currently cancelable, if not will only be canceled by hard EndAbility calls */
    //如果该技能当前可被取消,则返回 true;若不可取消,则只能通过强制调用结束技能的方法(EndAbility)来取消。
    UPROPERTY()
    bool bIsCancelable;

    /** True if the ability block flags are currently enabled */
    //如果当前技能的阻塞标志已启用,则返回 true
    UPROPERTY()
    bool bIsBlockingOtherAbilities;
临时字段

并发用锁,开发中应该不需要直接暴露并且使用

    /** A count of all the current scope locks. */
    //当前所有作用域锁的数量统计。
    mutable int8 ScopeLockCount;

    /** A list of all the functions waiting for the scope lock to end so they can run. */
    //这句话描述的是一个等待队列,其中存放着所有等待某个作用域锁(Scope Lock)释放,进而得以运行的函数。
    mutable TArray<FPostLockDelegate> WaitingToExecute;

    /** Increases the scope lock count. */
    //增加作用域锁
    void IncrementListLock() const;

    /** Decreases the scope lock count. Runs the waiting to execute delegates if the count drops to zero. */
    //这段描述涉及到作用域锁(Scope Lock)的管理逻辑。具体来说,它做了两件事:
    //一是减少作用域锁的计数,二是当计数降为 0 时,运行那些等待执行的委托(delegates)。
    void DecrementListLock() const;

 

 

   1 // Copyright Epic Games, Inc. All Rights Reserved.
   2 
   3 #pragma once
   4 
   5 #include "CoreMinimal.h"
   6 #include "UObject/ObjectMacros.h"
   7 #include "UObject/Object.h"
   8 #include "Templates/SubclassOf.h"
   9 #include "GameplayTagContainer.h"
  10 #include "GameplayEffectTypes.h"
  11 #include "GameplayAbilitySpec.h"
  12 #include "GameplayEffect.h"
  13 #include "Abilities/GameplayAbilityTypes.h"
  14 #include "GameplayTaskOwnerInterface.h"
  15 #include "Abilities/GameplayAbilityTargetTypes.h"
  16 #include "Net/Core/PushModel/PushModelMacros.h"
  17 #include "GameplayAbility.generated.h"
  18 
  19 class UAbilitySystemComponent;
  20 class UAnimMontage;
  21 class UGameplayAbility;
  22 class UGameplayTask;
  23 class UGameplayTasksComponent;
  24 
  25 struct FScopedCanActivateAbilityLogEnabler
  26 {
  27     //每一个创建的GA实对象那么记录实例数量的计数器增加
  28     FScopedCanActivateAbilityLogEnabler() { ++LogEnablerCounter; }
  29     //每一个GA对象被销毁,计数器减少
  30     ~FScopedCanActivateAbilityLogEnabler() { --LogEnablerCounter; }
  31     //静态成员函数,返回有多少个实例存在
  32     static bool IsLoggingEnabled() { return LogEnablerCounter > 0; }
  33 
  34 private:
  35     //静态成员变量
  36     //这是一个私有静态成员变量,用于跟踪当前有多少个 FScopedCanActivateAbilityLogEnabler 对象存在。
  37     //由于它是静态的,所有 FScopedCanActivateAbilityLogEnabler 对象共享同一个 LogEnablerCounter 变量。
  38     //私有的访问修饰符确保外部代码不能直接修改该变量,只能通过 FScopedCanActivateAbilityLogEnabler 的构造函数和析构函数来间接修改。
  39     static int32 LogEnablerCounter;
  40 };
  41 
  42 /**
  43  * UGameplayAbility
  44  *    
  45  *    Abilities define custom gameplay logic that can be activated or triggered.
  46  *    
  47  *    The main features provided by the AbilitySystem for GameplayAbilities are: 
  48  *        -CanUse functionality:
  49  *            -Cooldowns
  50  *            -Costs (mana, stamina, etc)
  51  *            -etc
  52  *            
  53  *        -Replication support
  54  *            -Client/Server communication for ability activation
  55  *            -Client prediction for ability activation
  56  *            
  57  *        -Instancing support
  58  *            -Abilities can be non-instanced (native only)
  59  *            -Instanced per owner
  60  *            -Instanced per execution (default)
  61  *            
  62  *        -Basic, extendable support for:
  63  *            -Input binding
  64  *            -'Giving' abilities (that can be used) to actors
  65  *    
  66  *
  67  *    See GameplayAbility_Montage for an example of a non-instanced ability
  68  *        -Plays a montage and applies a GameplayEffect to its target while the montage is playing.
  69  *        -When finished, removes GameplayEffect.
  70  *    
  71  *    Note on replication support:
  72  *        -Non instanced abilities have limited replication support. 
  73  *            -Cannot have state (obviously) so no replicated properties
  74  *            -RPCs on the ability class are not possible either.
  75  *            
  76  *    To support state or event replication, an ability must be instanced. This can be done with the InstancingPolicy property.
  77  */
  78 
  79 /** Notification delegate definition for when the gameplay ability ends */
  80 //用于GA结束时的委托,多播,单参数指向UGameplayAbility类对象的指针
  81 //这允许绑定的函数获取到结束的游戏玩法能力的具体实例,从而可以根据该实例的状态或属性进行相应的处理。
  82 DECLARE_MULTICAST_DELEGATE_OneParam(FOnGameplayAbilityEnded, UGameplayAbility*);
  83 
  84 /** Notification delegate definition for when the gameplay ability is cancelled */
  85 //GA取消时候的委托,多播,无参数,不需要通知
  86 DECLARE_MULTICAST_DELEGATE(FOnGameplayAbilityCancelled);
  87 
  88 /** Used to notify ability state tasks that a state is being ended */
  89 //多播委托,用于通知能力状态任务某个状态即将结束。在游戏玩法能力系统中,能力可能会有不同的状态,当某个状态结束时,就可以通过这个委托来通知相关的任务。
  90 //参数:携带一个 FName 类型的参数,FName 在虚幻引擎里是一种高效的字符串标识符,这里用它来表示即将结束的状态的名称,方便接收通知的任务明确具体是哪个状态结束了。
  91 DECLARE_MULTICAST_DELEGATE_OneParam(FOnGameplayAbilityStateEnded, FName);
  92 
  93 //用途:这是一个普通委托,只能绑定一个函数。它的作用是延迟函数的执行,直到程序离开某个关键区域(临界区)。使用这个委托可以确保某些操作在离开临界区后再执行,避免出现竞态条件等并发问题。
  94 //参数:该委托不携带任何参数,它主要关注的是在合适的时机执行绑定的函数,而不需要额外的上下文信息。
  95 DECLARE_DELEGATE(FPostLockDelegate);
  96 
  97 /** Structure that defines how an ability will be triggered by external events */
  98 //虚幻宏,为了在反射系统中被识别支持属性编辑与序列化等功能
  99 USTRUCT()
 100 struct FAbilityTriggerData
 101 {
 102     //相关的结构体代码宏
 103     GENERATED_USTRUCT_BODY()
 104 
 105     //在构造函数中,将 TriggerSource 成员变量初始化为 EGameplayAbilityTriggerSource::GameplayEvent,意味着默认的触发源类型是GE。
 106     FAbilityTriggerData() 
 107     : TriggerSource(EGameplayAbilityTriggerSource::GameplayEvent)
 108     {}
 109 
 110     /** The tag to respond to */
 111     //TriggerTag 是一个 FGameplayTag 类型的成员变量,用于指定GA要响应的标签。
 112     //在游戏玩法系统中,标签是一种轻量级的标识符,用于标记各种游戏元素或状态。
 113     //当系统检测到与 TriggerTag 匹配的标签出现时,可能会触发相应的能力。
 114     UPROPERTY(EditAnywhere, Category=TriggerData, meta=(Categories="TriggerTagCategory"))
 115     FGameplayTag TriggerTag;
 116 
 117     /** The type of trigger to respond to */
 118     //TriggerSource 是一个枚举类型的成员变量,使用 TEnumAsByte 进行包装,用于指定能力的触发源类型。
 119     //EGameplayAbilityTriggerSource::Type 是一个枚举类型,定义了不同的触发源类型,例如游戏玩法事件、输入事件等。
 120     UPROPERTY(EditAnywhere, Category=TriggerData)
 121     TEnumAsByte<EGameplayAbilityTriggerSource::Type> TriggerSource;
 122 };
 123 
 124 /** Abilities define custom gameplay logic that can be activated by players or external game logic */
 125 UCLASS(Blueprintable)
 126 class GAMEPLAYABILITIES_API UGameplayAbility : public UObject, public IGameplayTaskOwnerInterface
 127 {
 128     GENERATED_UCLASS_BODY()
 129     REPLICATED_BASE_CLASS(UGameplayAbility)
 130 
 131     friend class UAbilitySystemComponent;
 132     friend class UGameplayAbilitySet;
 133     friend struct FScopedTargetListLock;
 134 
 135 public:
 136 
 137     // ----------------------------------------------------------------------------------------------------------------
 138     //
 139     //    The important functions:
 140     //    
 141     //        CanActivateAbility()    - const function to see if ability is activatable. Callable by UI etc
 142     //
 143     //        TryActivateAbility()    - Attempts to activate the ability. Calls CanActivateAbility(). Input events can call this directly.
 144     //                                - Also handles instancing-per-execution logic and replication/prediction calls.
 145     //        
 146     //        CallActivateAbility()    - Protected, non virtual function. Does some boilerplate 'pre activate' stuff, then calls ActivateAbility()
 147     //
 148     //        ActivateAbility()        - What the abilities *does*. This is what child classes want to override.
 149     //    
 150     //        CommitAbility()            - Commits reources/cooldowns etc. ActivateAbility() must call this!
 151     //        
 152     //        CancelAbility()            - Interrupts the ability (from an outside source).
 153     //
 154     //        EndAbility()            - The ability has ended. This is intended to be called by the ability to end itself.
 155     //    
 156     // ----------------------------------------------------------------------------------------------------------------
 157 
 158     // --------------------------------------
 159     //    Accessors 访问器函数
 160     // --------------------------------------
 161 
 162     /** Returns how the ability is instanced when executed. This limits what an ability can do in its implementation. */
 163     //返回技能在执行时的实例化方式。这会限制技能在其实现过程中所能进行的操作。
 164     EGameplayAbilityInstancingPolicy::Type GetInstancingPolicy() const;
 165 
 166     /** How an ability replicates state/events to everyone on the network */
 167     //获取网络复制策略
 168     EGameplayAbilityReplicationPolicy::Type GetReplicationPolicy() const
 169     {
 170         return ReplicationPolicy;
 171     }
 172 
 173     /** Where does an ability execute on the network? Does a client "ask and predict", "ask and wait", "don't ask (just do it)" */
 174     //获取网络执行策略
 175     EGameplayAbilityNetExecutionPolicy::Type GetNetExecutionPolicy() const
 176     {
 177         return NetExecutionPolicy;
 178     }
 179 
 180     /** Where should an ability execute on the network? Provides protection from clients attempting to execute restricted abilities. */
 181     //网络安全策略
 182     EGameplayAbilityNetSecurityPolicy::Type GetNetSecurityPolicy() const
 183     {
 184         return NetSecurityPolicy;
 185     }
 186 
 187     /** Returns the actor info associated with this ability, has cached pointers to useful objects */
 188     //返回与此GA相关联的角色信息,其中包含指向有用对象的缓存指针
 189     UFUNCTION(BlueprintCallable, Category=Ability)
 190     FGameplayAbilityActorInfo GetActorInfo() const;
 191 
 192     /** Returns the actor that owns this ability, which may not have a physical location */
 193     //返回拥有此GA的角色(Actor),该角色可能没有实际的物理位置。
 194     UFUNCTION(BlueprintCallable, Category = Ability)
 195     AActor* GetOwningActorFromActorInfo() const;
 196 
 197     /** Returns the physical actor that is executing this ability. May be null */
 198     //返回正在执行此GA的实体角色(Actor)。该返回值可能为空。 
 199     UFUNCTION(BlueprintCallable, Category = Ability)
 200     AActor* GetAvatarActorFromActorInfo() const;
 201 
 202     /** Convenience method for abilities to get skeletal mesh component - useful for aiming abilities */
 203     //这是一个供GA使用的便捷方法,用于获取骨骼网格体组件,这对于需要进行瞄准操作的GA十分有用。 
 204     UFUNCTION(BlueprintCallable, DisplayName = "GetSkeletalMeshComponentFromActorInfo", Category = Ability)
 205     USkeletalMeshComponent* GetOwningComponentFromActorInfo() const;
 206 
 207     /** Returns the AbilitySystemComponent that is activating this ability */
 208     //返回正在激活此GA的AS组件。
 209     UFUNCTION(BlueprintCallable, Category = Ability)
 210     UAbilitySystemComponent* GetAbilitySystemComponentFromActorInfo() const;
 211 
 212     //已经废弃的
 213     UE_DEPRECATED(5.5, "Use GetAbilitySystemComponentFromActorInfo_Ensured")
 214     UAbilitySystemComponent* GetAbilitySystemComponentFromActorInfo_Checked() const;
 215     UAbilitySystemComponent* GetAbilitySystemComponentFromActorInfo_Ensured() const;
 216     
 217     /** The ability is considered to have these tags. */
 218     //该GA被认为具有这些标签。
 219     const FGameplayTagContainer& GetAssetTags() const;
 220 
 221     /** Gets the current actor info bound to this ability - can only be called on instanced abilities. */
 222     //获取绑定到此GA的当前角色信息 —— 此操作仅可对实例化技能调用。
 223     const FGameplayAbilityActorInfo* GetCurrentActorInfo() const;
 224 
 225     /** Gets the current activation info bound to this ability - can only be called on instanced abilities. */
 226     //获取绑定到此GA的当前激活信息 —— 此方法仅能在已实例化的技能上调用。 
 227     FGameplayAbilityActivationInfo GetCurrentActivationInfo() const;
 228 
 229     /** Gets the current activation info bound to this ability - can only be called on instanced abilities. */
 230     //获取绑定到该GA的当前激活信息 —— 此操作仅适用于已实例化的技能(即只能对实例化的GA调用此方法)。 
 231     FGameplayAbilityActivationInfo& GetCurrentActivationInfoRef()
 232     {
 233         checkf(IsInstantiated(), TEXT("%s: GetCurrentActivationInfoRef cannot be called on a non-instanced ability. Check the instancing policy."), *GetPathName());
 234         return CurrentActivationInfo;
 235     }
 236 
 237     /** Gets the current AbilitySpecHandle- can only be called on instanced abilities. */
 238     //获取当前的技能规格句柄(AbilitySpecHandle)—— 此操作仅能在已实例化的技能上调用。
 239     //在游戏开发尤其是使用虚幻引擎的技能系统时,AbilitySpecHandle 是一个用于标识特定技能实例的句柄,通过它可以方便地对技能进行管理和操作。这里强调只能在实例化技能上调用获取该句柄的方法,
 240     //是因为非实例化技能没有这样独立的、可标识的实例,也就不存在对应的句柄。
 241     //************非常重要****************
 242     FGameplayAbilitySpecHandle GetCurrentAbilitySpecHandle() const;
 243 
 244     /** Retrieves the actual AbilitySpec for this ability. Can only be called on instanced abilities. */
 245     //检索此技能的实际技能规格(AbilitySpec)。此操作仅可在已实例化的技能上调用。
 246     //解释
 247     //在游戏开发的技能系统语境里,AbilitySpec 包含了技能的详细配置信息,比如技能等级、输入绑定等。
 248     //只有实例化的技能才拥有独立的、可获取的 AbilitySpec,非实例化技能由于不具备独立的实例状态,所以不能调用该方法来获取 AbilitySpec。
 249     FGameplayAbilitySpec* GetCurrentAbilitySpec() const;
 250 
 251     /** Retrieves the EffectContext of the GameplayEffect that granted this ability. Can only be called on instanced abilities. */
 252     //检索授予此技能的游戏玩法效果(GameplayEffect)的效果上下文(EffectContext)。此操作仅可在已实例化的技能上调用。
 253     //在游戏开发中,尤其是涉及技能系统时,GameplayEffect 可以用来授予角色技能。而 EffectContext 则包含了与该效果相关的额外信息,例如伤害来源、目标对象等上下文数据。
 254     //因为非实例化技能没有独立的状态和执行上下文,所以只有实例化的技能才能获取授予它的 GameplayEffect 的 EffectContext 。
 255     UFUNCTION(BlueprintCallable, Category = Ability)
 256     FGameplayEffectContextHandle GetGrantedByEffectContext() const;
 257 
 258     /** Generates a GameplayEffectContextHandle from our owner and an optional TargetData.*/
 259     //根据我们的所有者(拥有该技能的对象)以及一个可选的目标数据,生成一个游戏玩法效果上下文句柄(GameplayEffectContextHandle)。 
 260     UFUNCTION(BlueprintCallable, Category = Ability)
 261     virtual FGameplayEffectContextHandle GetContextFromOwner(FGameplayAbilityTargetDataHandle OptionalTargetData) const;
 262 
 263     /** Returns an effect context, given a specified actor info */
 264     //根据指定的角色信息返回一个效果上下文。
 265     virtual FGameplayEffectContextHandle MakeEffectContext(const FGameplayAbilitySpecHandle Handle, const FGameplayAbilityActorInfo *ActorInfo) const;
 266 
 267     /** Convenience method for abilities to get outgoing gameplay effect specs (for example, to pass on to projectiles to apply to whoever they hit) */
 268     //这是一个供技能使用的便捷方法,用于获取传出的游戏玩法效果规格(例如,将其传递给投射物,以便投射物击中目标时应用这些效果)。
 269     //在游戏开发中,技能常常会产生各种游戏玩法效果(Gameplay Effect),比如伤害、减速、眩晕等。这些效果需要有具体的规格(Spec)来定义其属性,如伤害值、持续时间等。
 270     //“outgoing gameplay effect specs” 指的是从技能发出、准备应用到目标上的效果规格。这个便捷方法可以让技能方便地获取这些规格。
 271     //以投射物为例,当技能发射一个投射物时,可能希望投射物在击中目标时应用某些效果,比如火焰伤害、中毒效果等。通过这个方法,
 272     //技能可以获取这些效果规格,并将其传递给投射物,这样投射物在击中目标时就能正确地应用这些效果。
 273     //**************************************************************非常常用的东西************************************************************************//
 274     UFUNCTION(BlueprintCallable, Category=Ability)
 275     FGameplayEffectSpecHandle MakeOutgoingGameplayEffectSpec(TSubclassOf<UGameplayEffect> GameplayEffectClass, float Level=1.f) const;
 276 
 277     /** Native version of above function */
 278     //上述函数的原生版本
 279     //不支持BP的版本
 280     virtual FGameplayEffectSpecHandle MakeOutgoingGameplayEffectSpec(const FGameplayAbilitySpecHandle Handle, const FGameplayAbilityActorInfo* ActorInfo, const FGameplayAbilityActivationInfo ActivationInfo, TSubclassOf<UGameplayEffect> GameplayEffectClass, float Level = 1.f) const;
 281 
 282     /** Add the Ability's tags to the given GameplayEffectSpec. This is likely to be overridden per project. */
 283     //将该技能的标签添加到给定的游戏玩法效果规格(GameplayEffectSpec)中。此操作很可能需要针对每个项目进行重写。
 284     //在游戏开发的技能系统里,技能和游戏玩法效果通常会使用标签(Tags)来进行分类和标记。技能标签可以描述技能的特性,比如 “伤害技能”“治疗技能”“近战技能” 等;
 285     //而游戏玩法效果规格则定义了某个效果的具体参数,像伤害值、持续时间等。
 286     virtual void ApplyAbilityTagsToGameplayEffectSpec(FGameplayEffectSpec& Spec, FGameplayAbilitySpec* AbilitySpec) const;
 287 
 288     /** Returns true if the ability is currently active */
 289     //把技能的标签添加到游戏玩法效果规格中,意味着让这个效果带有该技能的一些特性信息。这样在后续处理效果时,
 290     //可以根据这些标签来进行不同的逻辑判断,例如根据标签决定是否触发额外的效果,或者是否对特定类型的目标生效等。
 291     //**************************************************************非常常用的东西************************************************************************//
 292     bool IsActive() const;
 293 
 294     /** Is this ability triggered from TriggerData (or is it triggered explicitly through input/game code) */
 295     //这个技能是由触发数据(TriggerData)触发的,还是通过输入(比如玩家按键等操作)或游戏代码显式触发的呢?
 296     bool IsTriggered() const;
 297 
 298     /** Is this ability running on a a predicting client, this is false in single player */
 299     //这个技能是否正在预测型客户端上运行?在单人游戏中此值为 false。
 300     //这里提到的 “预测型客户端(predicting client)” 就是指使用了客户端预测机制的客户端。如果技能在这样的客户端上运行,就可以利用客户端预测来优化技能表现。
 301     //而在单人游戏中,不存在客户端和服务器之间的交互以及客户端预测的需求,所以这个判定条件就会是 false。
 302     bool IsPredictingClient() const;
 303 
 304     /** True if this is on the server and is being executed for a non-local player, false in single player */
 305     //如果此操作发生在服务器端,并且是为非本地玩家执行的,则返回 true;在单人游戏中返回 false。
 306     bool IsForRemoteClient() const;
 307 
 308     /** True if the owning actor is locally controlled, true in single player */
 309     //如果拥有该技能的角色是由本地进行控制的,则返回 true;在单人游戏中也返回 true。
 310     UFUNCTION(BlueprintCallable, BlueprintPure = false, Category = Ability, Meta = (ExpandBoolAsExecs = "ReturnValue"))
 311     bool IsLocallyControlled() const;
 312 
 313     /** True if this is the server or single player */
 314     //如果当前处于服务器端或者是单人游戏环境,该条件为真。
 315     bool HasAuthority(const FGameplayAbilityActivationInfo* ActivationInfo) const;
 316 
 317     UFUNCTION(BlueprintCallable, BlueprintPure = false, Category = Ability, DisplayName = "HasAuthority", Meta = (ExpandBoolAsExecs = "ReturnValue"))
 318     //非BP版本
 319     bool K2_HasAuthority() const;
 320 
 321     /** True if we are authority or we have a valid prediciton key that is expected to work */
 322     //如果我们拥有控制权(即处于权威状态),或者我们有一个预期有效的有效预测键,那么该条件为真。
 323     bool HasAuthorityOrPredictionKey(const FGameplayAbilityActorInfo* ActorInfo, const FGameplayAbilityActivationInfo* ActivationInfo) const;
 324 
 325     /** True if this has been instanced, always true for blueprints */
 326     //如果该对象已被实例化,则此条件为 true;对于蓝图而言,此条件始终为 true。
 327     //蓝图的特殊性
 328     //在虚幻引擎等游戏开发工具中,蓝图是一种可视化的脚本编程方式。蓝图本质上可以看作是已经实例化好的对象,它们自带一些默认的配置和行为,并且可以直接在场景中使用。
 329     //所以对于蓝图来说,“是否已实例化” 这个判断条件始终为 true,因为蓝图本身就已经是具体的实例,不需要像普通类那样再进行显式的实例化操作。
 330     bool IsInstantiated() const;
 331 
 332     /** Notification that the ability has ended.  Set using TryActivateAbility. */
 333     //这是一个关于技能结束的通知。该通知通过调用 TryActivateAbility 方法来设置。
 334     //在游戏开发的技能系统中,技能通常有激活和结束等不同的状态。当技能从激活状态转变为结束状态时,系统需要发出相应的通知,以便游戏的其他部分(如界面显示、音效播放、状态更新等)做出响应。
 335     //TryActivateAbility 是一个常用的用于尝试激活技能的方法。在技能激活之后,当技能满足结束条件(比如技能持续时间结束、被打断等),
 336     //就会触发这个技能结束的通知。通过这个通知,开发者可以在技能结束时执行一些特定的逻辑,例如停止技能相关的动画、回收资源、更新角色状态等。
 337     FOnGameplayAbilityEnded OnGameplayAbilityEnded;
 338 
 339     /** Notification that the ability has ended with data on how it was ended */
 340     //这是一个技能结束的通知,并且该通知附带了关于技能是如何结束的相关数据。
 341     //在游戏开发里,技能系统通常会涉及技能的激活、执行以及结束等不同阶段。当技能结束时,系统发送的通知除了告知技能已结束这一基本信息外,还会携带技能结束方式的相关数据。
 342     //这些关于技能结束方式的数据可能包含多种情况,比如:
 343     //正常结束:技能按照预设的持续时间自然完成,通知数据里可能会包含技能实际持续的时长。
 344     //被打断结束:技能在执行过程中被其他事件打断,如角色受到控制效果、被攻击等,通知数据可能会说明打断技能的具体原因和来源。
 345     //条件不满足结束:技能执行过程中某些必要条件不再满足,例如技能所需的资源耗尽,通知数据会指明是哪种条件不满足导致技能结束。
 346     FGameplayAbilityEndedDelegate OnGameplayAbilityEndedWithData;
 347 
 348     /** Notification that the ability is being cancelled.  Called before OnGameplayAbilityEnded. */
 349     //这是一个关于技能正在被取消的通知。该通知会在 OnGameplayAbilityEnded(技能结束事件)被调用之前触发。
 350     //在游戏的技能系统中,技能可能会因为各种原因被取消,比如玩家主动取消技能释放、角色受到某些控制效果(如眩晕、沉默)影响而不得不中断技能等。
 351     //当技能开始被取消时,系统会发出这个 “技能正在被取消” 的通知。这个通知的作用在于,让开发者有机会在技能真正结束之前执行一些特定的操作,例如播放取消技能的动画、停止技能正在进行的特效、保存一些临时数据等。
 352     //而 OnGameplayAbilityEnded 是技能结束时触发的事件,通常用于进行技能结束后的清理工作,如释放占用的资源、更新角色状态等。
 353     //由于 “技能正在被取消” 是技能结束流程的一个前置阶段,所以该通知会在 OnGameplayAbilityEnded 之前被调用,以保证整个技能取消和结束的流程有序进行。
 354     FOnGameplayAbilityCancelled OnGameplayAbilityCancelled;
 355     
 356     /** Used by the ability state task to handle when a state is ended */
 357     //这用于技能状态任务(ability state task)处理状态结束的情况。
 358     //详细解释
 359     //在游戏开发的技能系统里,技能往往会有不同的状态,例如准备状态、激活状态、冷却状态等。技能状态任务则是负责管理和执行与技能状态相关操作的组件。
 360     //当某个技能状态结束时,就需要有相应的机制来处理这种状态转变。这里提到的这个机制或者功能,就是专门供技能状态任务在遇到状态结束情况时使用的。
 361     //它可能包含的操作有:
 362     //状态切换:将技能从当前结束的状态切换到下一个合适的状态,比如从激活状态结束后进入冷却状态。
 363     //数据清理:清除与已结束状态相关的临时数据或标记,为新状态做好准备。
 364     //触发事件:发送状态结束的通知,让游戏的其他部分(如界面显示、音效系统等)做出响应。
 365     FOnGameplayAbilityStateEnded OnGameplayAbilityStateEnded;
 366 
 367     /** Callback for when this ability has been confirmed by the server */
 368     //这是一个回调函数,用于处理当该技能被服务器确认的情况。
 369     FGenericAbilityDelegate    OnConfirmDelegate;
 370 
 371     // --------------------------------------
 372     //    CanActivateAbility
 373     // --------------------------------------
 374 
 375     /** Returns true if this ability can be activated right now. Has no side effects */
 376     //这句话描述的是一个用于判断技能当前是否可以激活的功能。下面为你详细解释:
 377     //该功能会返回一个布尔值(true 或 false),用于表示当前这个技能是否能够被激活。并且,执行这个判断操作不会对游戏的状态或其他方面产生任何附带的影响,也就是所谓的 “没有副作用(Has no side effects)”。
 378     //技能激活条件判断
 379     //在游戏开发中,技能通常有一系列的激活条件,例如:
 380     //@资源条件:玩家可能需要消耗一定的魔法值、体力值等资源才能释放技能。如果当前资源不足,技能就不能被激活。
 381     //@冷却时间:为了避免玩家无限制地使用技能,技能往往有冷却时间的限制。如果技能还处于冷却状态,那么它就无法被激活。
 382     //@目标条件:某些技能需要有合适的目标才能释放,比如指向性技能需要玩家选中有效的目标。如果没有满足要求的目标,技能也不能激活。
 383     //@角色状态:玩家角色可能处于某些特殊状态,例如被眩晕、沉默等控制效果影响,此时技能也无法激活。
 384     //这个功能会综合考虑这些条件,判断技能在当前时刻是否满足激活的要求,并返回相应的布尔值。
 385     virtual bool CanActivateAbility(const FGameplayAbilitySpecHandle Handle, const FGameplayAbilityActorInfo* ActorInfo, const FGameplayTagContainer* SourceTags = nullptr, const FGameplayTagContainer* TargetTags = nullptr, OUT FGameplayTagContainer* OptionalRelevantTags = nullptr) const;
 386 
 387     /** Returns true if this ability can be triggered right now. Has no side effects */
 388     //此函数用于判断当前技能是否能够立即被触发,并且执行该判断操作不会对游戏状态产生任何附带影响(即无副作用)。
 389     virtual bool ShouldAbilityRespondToEvent(const FGameplayAbilityActorInfo* ActorInfo, const FGameplayEventData* Payload) const;
 390 
 391     /** Returns true if an an ability should be activated */
 392     //这个功能是用于判断某个技能是否应该被激活,并返回一个布尔值。如果判断结果为技能应该被激活,函数返回 true;反之则返回 false。
 393     virtual bool ShouldActivateAbility(ENetRole Role) const;
 394 
 395     /** Returns the time in seconds remaining on the currently active cooldown. */
 396     //该功能用于返回当前技能处于激活冷却状态时,剩余的冷却时间(以秒为单位)。
 397     //****很重要了*****
 398     UFUNCTION(BlueprintCallable, Category = Ability)
 399     float GetCooldownTimeRemaining() const;
 400 
 401     /** Returns the time in seconds remaining on the currently active cooldown. */
 402     //此函数的作用是返回当前技能处于激活冷却状态时所剩余的冷却时间,时间单位为秒。
 403     //
 404     virtual float GetCooldownTimeRemaining(const FGameplayAbilityActorInfo* ActorInfo) const;
 405 
 406     /** Returns the time in seconds remaining on the currently active cooldown and the original duration for this cooldown. */
 407     //这个功能旨在返回当前技能正在进行的冷却状态下,剩余的冷却时间(以秒为单位)以及该次冷却的原始总时长。
 408     //这样的设计能让开发者和玩家同时了解到技能当前的冷却进度以及完整的冷却周期信息。
 409     virtual void GetCooldownTimeRemainingAndDuration(FGameplayAbilitySpecHandle Handle, const FGameplayAbilityActorInfo* ActorInfo, float& TimeRemaining, float& CooldownDuration) const;
 410 
 411     /** Returns all tags that can put this ability into cooldown */
 412     //这个功能是用于返回所有能够使某个GA进入冷却状态的标签(Tags)
 413     //
 414     virtual const FGameplayTagContainer* GetCooldownTags() const;
 415     
 416     /** Returns true if none of the ability's tags are blocked and if it doesn't have a "Blocking" tag and has all "Required" tags. */
 417     //这个功能主要用于判断一个技能(能力,Ability)是否可以激活。它会检查技能的标签(Tags)情况,当满足以下三个条件时返回 true,否则返回 false:
 418     //这个功能主要用于判断一个技能(能力,Ability)是否可以激活。它会检查技能的标签(Tags)情况,当满足以下三个条件时返回 true,否则返回 false:
 419     //技能的所有标签都未被阻止(即没有被游戏机制禁止使用)。
 420     //技能本身不带有 “Blocking” 标签。
 421     //技能拥有所有 “Required” 标签。
 422     virtual bool DoesAbilitySatisfyTagRequirements(const UAbilitySystemComponent& AbilitySystemComponent, const FGameplayTagContainer* SourceTags = nullptr, const FGameplayTagContainer* TargetTags = nullptr, OUT FGameplayTagContainer* OptionalRelevantTags = nullptr) const;
 423 
 424     /** Returns true if this ability is blocking other abilities */
 425     //这个功能用于判断当前GA(能力,Ability)是否正在阻止其他技能的使用。
 426     virtual bool IsBlockingOtherAbilities() const;
 427 
 428     /** Sets rather ability block flags are enabled or disabled. Only valid on instanced abilities */
 429     //此功能用于设置GA(能力,Ability)的阻塞标志(block flags)是启用还是禁用。不过,该设置仅对已实例化的技能有效。
 430     UFUNCTION(BlueprintCallable, Category = Ability)
 431     virtual void SetShouldBlockOtherAbilities(bool bShouldBlockAbilities);
 432 
 433     // --------------------------------------
 434     //    CancelAbility
 435     // --------------------------------------
 436 
 437     /** Destroys instanced-per-execution abilities. Instance-per-actor abilities should 'reset'. Any active ability state tasks receive the 'OnAbilityStateInterrupted' event. Non instance abilities - what can we do? */
 438     //销毁每次执行时实例化的能力。每个角色实例化的能力应该“重置”。任何处于激活状态的能力状态任务都会收到“能力状态中断”事件。对于非实例化能力 - 我们能做些什么呢? 
 439     virtual void CancelAbility(const FGameplayAbilitySpecHandle Handle, const FGameplayAbilityActorInfo* ActorInfo, const FGameplayAbilityActivationInfo ActivationInfo, bool bReplicateCancelAbility);
 440 
 441     /** Call from Blueprint to cancel the ability naturally */
 442     //从蓝图中调用,以正常取消该技能。
 443     UFUNCTION(BlueprintCallable, Category = Ability, DisplayName = "CancelAbility", meta=(ScriptName = "CancelAbility"))
 444     void K2_CancelAbility();
 445 
 446     /** Returns true if this ability can be canceled */
 447     //如果此技能可以被取消,则返回 true。
 448     virtual bool CanBeCanceled() const;
 449 
 450     /** Sets whether the ability should ignore cancel requests. Only valid on instanced abilities */
 451     //设置该技能是否应忽略取消请求。此设置仅对实例化技能有效。
 452     UFUNCTION(BlueprintCallable, Category=Ability)
 453     virtual void SetCanBeCanceled(bool bCanBeCanceled);
 454 
 455     // --------------------------------------
 456     //    CommitAbility
 457     // --------------------------------------
 458 
 459     /** Attempts to commit the ability (spend resources, etc). This our last chance to fail. Child classes that override ActivateAbility must call this themselves! */
 460     //尝试提交技能(消耗资源等)。这是我们最后一次允许技能激活失败的机会。重写了 `ActivateAbility` 方法的子类必须自行调用此方法!
 461     //ue5.3以后就变成了commit
 462     //
 463     UFUNCTION(BlueprintCallable, Category = Ability, DisplayName = "CommitAbility", meta=(ScriptName = "CommitAbility"))
 464     virtual bool K2_CommitAbility();
 465 
 466     /** Attempts to commit the ability's cooldown only. If BroadcastCommitEvent is true, it will broadcast the commit event that tasks like WaitAbilityCommit are listening for. */
 467     //仅尝试触发技能的冷却机制。若 “BroadcastCommitEvent(广播技能激活事件)” 参数设为 “true”,
 468     //则会广播激活事件,诸如 “WaitAbilityCommit(等待技能激活)” 这类任务会监听此事件。
 469     UFUNCTION(BlueprintCallable, Category = Ability, DisplayName = "CommitAbilityCooldown", meta=(ScriptName = "CommitAbilityCooldown"))
 470     virtual bool K2_CommitAbilityCooldown(bool BroadcastCommitEvent=false, bool ForceCooldown=false);
 471 
 472     /** Attempts to commit the ability's cost only. If BroadcastCommitEvent is true, it will broadcast the commit event that tasks like WaitAbilityCommit are listening for. */
 473     //仅尝试消耗该技能的使用成本(如消耗魔法值、资源等)。如果 “BroadcastCommitEvent”(广播技能激活事件)参数为 “true”,
 474     //则会广播技能激活事件,像 “WaitAbilityCommit”(等待技能激活)这类任务会监听此事件。
 475     UFUNCTION(BlueprintCallable, Category = Ability, DisplayName = "CommitAbilityCost", meta=(ScriptName = "CommitAbilityCost"))
 476     virtual bool K2_CommitAbilityCost(bool BroadcastCommitEvent=false);
 477 
 478     /** Checks the ability's cooldown, but does not apply it.*/
 479     //检查技能的冷却时间,但不应用该冷却(即不会触发技能进入冷却状态)。 
 480     UFUNCTION(BlueprintCallable, Category = Ability, DisplayName = "CheckAbilityCooldown", meta=(ScriptName = "CheckAbilityCooldown"))
 481     virtual bool K2_CheckAbilityCooldown();
 482 
 483     /** Checks the ability's cost, but does not apply it. */
 484     //检查该技能的使用成本(如魔法值、体力、特殊资源等),但不进行实际消耗。 
 485     UFUNCTION(BlueprintCallable, Category = Ability, DisplayName = "CheckAbilityCost", meta=(ScriptName = "CheckAbilityCost"))
 486     virtual bool K2_CheckAbilityCost();
 487 
 488     //几个虚函数
 489     virtual bool CommitAbility(const FGameplayAbilitySpecHandle Handle, const FGameplayAbilityActorInfo* ActorInfo, const FGameplayAbilityActivationInfo ActivationInfo, OUT FGameplayTagContainer* OptionalRelevantTags = nullptr);
 490     virtual bool CommitAbilityCooldown(const FGameplayAbilitySpecHandle Handle, const FGameplayAbilityActorInfo* ActorInfo, const FGameplayAbilityActivationInfo ActivationInfo, const bool ForceCooldown, OUT FGameplayTagContainer* OptionalRelevantTags = nullptr);
 491     virtual bool CommitAbilityCost(const FGameplayAbilitySpecHandle Handle, const FGameplayAbilityActorInfo* ActorInfo, const FGameplayAbilityActivationInfo ActivationInfo, OUT FGameplayTagContainer* OptionalRelevantTags = nullptr);
 492 
 493     /** The last chance to fail before committing, this will usually be the same as CanActivateAbility. Some abilities may need to do extra checks here if they are consuming extra stuff in CommitExecute */
 494     //这是在提交技能(如消耗资源等操作)之前允许技能激活失败的最后机会,此检查通常与 `CanActivateAbility`(能否激活技能)的检查相同。
 495     //不过,有些技能如果在 `CommitExecute`(提交执行)阶段会消耗额外的资源或满足额外条件,可能需要在此处进行额外的检查。 
 496     virtual bool CommitCheck(const FGameplayAbilitySpecHandle Handle, const FGameplayAbilityActorInfo* ActorInfo, const FGameplayAbilityActivationInfo ActivationInfo, OUT FGameplayTagContainer* OptionalRelevantTags = nullptr);
 497 
 498     /** BP event called from CommitAbility */
 499     //从 CommitAbility(提交技能)调用的蓝图(Blueprint,简称 BP)事件。
 500     //在游戏开发里,CommitAbility 通常是技能系统里用于确认技能激活、消耗资源并触发技能效果的函数。
 501     //当调用这个函数时,可能会触发一个蓝图事件,开发者能在蓝图可视化编辑环境里对该事件进行响应,编写自定义逻辑,像播放动画、生成特效、处理伤害计算等操作。
 502     UFUNCTION(BlueprintImplementableEvent, Category = Ability, DisplayName = "CommitExecute", meta = (ScriptName = "CommitExecute"))
 503     void K2_CommitExecute();
 504 
 505     /** Does the commit atomically (consume resources, do cooldowns, etc) */
 506     //以原子操作的方式执行提交操作(消耗资源、启动冷却时间等)。
 507     virtual void CommitExecute(const FGameplayAbilitySpecHandle Handle, const FGameplayAbilityActorInfo* ActorInfo, const FGameplayAbilityActivationInfo ActivationInfo);
 508 
 509     /** Returns the gameplay effect used to determine cooldown */
 510     //返回用于确定冷却时间的GE效果。
 511     virtual UGameplayEffect* GetCooldownGameplayEffect() const;
 512 
 513     /** Returns the gameplay effect used to apply cost */
 514     //返回用于应用GA COST的GE。
 515     virtual UGameplayEffect* GetCostGameplayEffect() const;
 516 
 517     /** Checks cooldown. returns true if we can be used again. False if not */
 518     //检查技能的冷却状态。如果技能可以再次使用,则返回 `true`;反之则返回 `false`。 
 519     virtual bool CheckCooldown(const FGameplayAbilitySpecHandle Handle, const FGameplayAbilityActorInfo* ActorInfo, OUT FGameplayTagContainer* OptionalRelevantTags = nullptr) const;
 520 
 521     /** Applies CooldownGameplayEffect to the target */
 522     //将冷却时间游戏玩法效果应用到目标上。
 523     //在游戏开发的技能系统中,“CooldownGameplayEffect” 一般是指用来实现技能冷却机制的一种游戏玩法效果,这种效果可能包含了冷却时间的具体数值、冷却时间的起始和结束逻辑等。
 524     //当调用此操作时,意味着会让目标(通常是技能的使用者)进入该技能的冷却状态,开始计算冷却时间,在冷却时间内该技能无法再次使用。
 525     virtual void ApplyCooldown(const FGameplayAbilitySpecHandle Handle, const FGameplayAbilityActorInfo* ActorInfo, const FGameplayAbilityActivationInfo ActivationInfo) const;
 526 
 527     /** Checks cost. returns true if we can pay for the ability. False if not */
 528     //检查COST。如果有足够资源来使用该技能,则返回 `true`;反之则返回 `false`。
 529     //**********很重要
 530     virtual bool CheckCost(const FGameplayAbilitySpecHandle Handle, const FGameplayAbilityActorInfo* ActorInfo, OUT FGameplayTagContainer* OptionalRelevantTags = nullptr) const;
 531 
 532     /** Applies the ability's cost to the target */
 533     //将该技能的COST施加到目标上。
 534     virtual void ApplyCost(const FGameplayAbilitySpecHandle Handle, const FGameplayAbilityActorInfo* ActorInfo, const FGameplayAbilityActivationInfo ActivationInfo) const;
 535 
 536     // --------------------------------------
 537     //    Input
 538     // --------------------------------------
 539 
 540     /** Input binding stub. */
 541     //输入绑定存根
 542     virtual void InputPressed(const FGameplayAbilitySpecHandle Handle, const FGameplayAbilityActorInfo* ActorInfo, const FGameplayAbilityActivationInfo ActivationInfo) {};
 543 
 544     /** Input binding stub. */
 545     //输入绑定存根
 546     virtual void InputReleased(const FGameplayAbilitySpecHandle Handle, const FGameplayAbilityActorInfo* ActorInfo, const FGameplayAbilityActivationInfo ActivationInfo) {};
 547 
 548     /** Called from AbilityTask_WaitConfirmCancel to handle input confirming */
 549     //从 AbilityTask_WaitConfirmCancel(等待确认或取消的技能任务)调用此函数,以处理输入确认操作。
 550     virtual void OnWaitingForConfirmInputBegin() {}
 551     virtual void OnWaitingForConfirmInputEnd() {}
 552 
 553     // --------------------------------------
 554     //    Animation
 555     // --------------------------------------
 556 
 557     /** Returns the currently playing montage for this ability, if any */
 558     //返回该技能当前正在播放的蒙太奇(Montage),如果有的话。
 559     UFUNCTION(BlueprintCallable, Category = Animation)
 560     UAnimMontage* GetCurrentMontage() const;
 561 
 562     /** Call to set/get the current montage from a montage task. Set to allow hooking up montage events to ability events */
 563     //此调用用于从蒙太奇任务中设置或获取当前的蒙太奇。进行设置是为了将蒙太奇事件与技能事件关联起来。
 564     virtual void SetCurrentMontage(class UAnimMontage* InCurrentMontage);
 565 
 566     /** Movement Sync */
 567     //不用了
 568     UE_DEPRECATED(5.3, "This serves no purpose and will be removed in future engine versions")
 569     virtual void SetMovementSyncPoint(FName SyncName);
 570 
 571     // ----------------------------------------------------------------------------------------------------------------
 572     //    Ability Levels and source objects 
 573     // ----------------------------------------------------------------------------------------------------------------
 574     
 575     /** Returns current level of the Ability */
 576     //返回该技能的当前等级。
 577     //在游戏的技能系统中,技能通常会有不同的等级,等级的提升可能会带来技能效果的增强,比如更高的伤害、更长的持续时间、更短的冷却时间等。
 578     //这个函数的作用就是获取该技能目前所处的等级,开发者可以根据这个等级来决定技能在不同阶段的具体表现和参数。
 579     UFUNCTION(BlueprintCallable, Category = Ability)
 580     int32 GetAbilityLevel() const;
 581 
 582     /** Returns current ability level for non instanced abilities. You must call this version in these contexts! */
 583     //返回非实例化技能的当前技能等级。在这些情况下,你必须调用此版本的函数!
 584     int32 GetAbilityLevel(FGameplayAbilitySpecHandle Handle, const FGameplayAbilityActorInfo* ActorInfo) const;
 585 
 586     /** Returns current ability level for non instanced abilities. You must call this version in these contexts! */
 587     //这个功能是专门针对非实例化技能(abilities)设计的,用于返回当前技能的等级。同时,在处理非实例化技能的相关情境下,必须调用此版本的函数来获取技能等级。
 588     UFUNCTION(BlueprintCallable, Category = Ability, meta = (DisplayName = "GetAbilityLevelNonInstanced", ReturnDisplayName = "AbilityLevel"))
 589     int32 GetAbilityLevel_BP(FGameplayAbilitySpecHandle Handle, const FGameplayAbilityActorInfo& ActorInfo) const;
 590 
 591     /** Retrieves the SourceObject associated with this ability. Can only be called on instanced abilities. */
 592     //这个功能用于获取与当前GA(能力,Ability)相关联的源对象(SourceObject)。不过,该操作只能在已实例化的技能上执行。
 593     UFUNCTION(BlueprintCallable, Category = Ability)
 594     UObject* GetCurrentSourceObject() const;
 595 
 596     /** Retrieves the SourceObject associated with this ability. Callable on non instanced */
 597     //此功能用于获取与当前技能(能力,Ability)相关联的源对象(SourceObject),并且该操作可在非实例化技能上调用。
 598     UObject* GetSourceObject(FGameplayAbilitySpecHandle Handle, const FGameplayAbilityActorInfo* ActorInfo) const;
 599 
 600     /** Retrieves the SourceObject associated with this ability. Callable on non instanced */
 601     //此功能允许从一个非实例化的技能(能力,Ability)中获取与之关联的源对象(SourceObject)。
 602     //在游戏开发的技能系统里,源对象通常代表技能效果的发起者或者根源,
 603     //获取它有助于在不同情境下处理技能相关的逻辑,即便该技能并非以实例化形式存在。
 604     UFUNCTION(BlueprintCallable, Category = Ability, meta = (DisplayName = "GetSourceObjectNonInstanced", ReturnDisplayName = "SourceObject"))
 605     UObject* GetSourceObject_BP(FGameplayAbilitySpecHandle Handle, const FGameplayAbilityActorInfo& ActorInfo) const;
 606 
 607     // --------------------------------------
 608     //    Interaction with ability system component
 609     // --------------------------------------
 610 
 611     /** Called by ability system component to inform this ability instance the remote instance was ended */
 612     //这是一个由技能系统组件(Ability System Component)调用的函数,其作用是通知当前技能实例(ability instance),
 613     //与之对应的远程实例已经结束。在多人游戏或者分布式游戏系统中,技能可能会在本地和远程的不同客户端或服务器实例上同时运行,
 614     //当远程的技能实例结束时,需要有一种机制来通知本地的对应实例,以便本地实例做出相应的处理
 615     virtual void SetRemoteInstanceHasEnded();
 616 
 617     /** Called to inform the ability that the AvatarActor has been replaced. If the ability is dependent on avatar state, it may want to end itself. */
 618     //这个功能是一个回调通知机制,当技能(能力,Ability)所关联的化身角色(AvatarActor)被替换时,
 619     //系统会调用此函数告知该技能。若技能的运行依赖于化身角色的状态,那么在接收到此通知后,技能可能会选择自行结束。
 620     virtual void NotifyAvatarDestroyed();
 621 
 622     /** Called to inform the ability that a task is waiting for the player to do something */
 623     //此功能是一个回调机制,当技能中的某个任务需要等待玩家执行特定操作时,系统会调用该函数来通知技能。
 624     //这使得技能能够知晓当前存在等待玩家交互的情况,并可以根据这一情况做出相应的处理。
 625     virtual void NotifyAbilityTaskWaitingOnPlayerData(class UAbilityTask* AbilityTask);
 626 
 627     /** Called to inform the ability that a task is waiting for the player's avatar to do something in world */
 628     //这是一个回调函数,当技能中的某个任务需要等待玩家操控的化身角色(在游戏世界里通常代表玩家本人的角色实体)完成特定动作或达到特定状态时,
 629     //系统会调用此函数来通知该技能。通过这种机制,技能能够感知到任务的等待状态,并根据情况做出相应的响应和处理。
 630     virtual void NotifyAbilityTaskWaitingOnAvatar(class UAbilityTask* AbilityTask);
 631 
 632     /** Called when the ability is given to an AbilitySystemComponent */
 633     //这是一个回调函数,当一个技能(能力,Ability)被赋予给技能系统组件(AbilitySystemComponent)时会触发该函数调用。
 634     //技能系统组件通常负责管理和执行角色所拥有的各种技能,而这个回调函数允许开发者在技能被添加到组件时执行特定的初始化或其他逻辑操作。
 635     virtual void OnGiveAbility(const FGameplayAbilityActorInfo* ActorInfo, const FGameplayAbilitySpec& Spec);
 636 
 637     /** Called when the ability is removed from an AbilitySystemComponent */
 638     //这是一个回调函数,当一个技能(能力,Ability)被赋予给技能系统组件(AbilitySystemComponent)时会触发该函数调用。
 639     //技能系统组件通常负责管理和执行角色所拥有的各种技能,而这个回调函数允许开发者在技能被添加到组件时执行特定的初始化或其他逻辑操作。
 640     virtual void OnRemoveAbility(const FGameplayAbilityActorInfo* ActorInfo, const FGameplayAbilitySpec& Spec) {}
 641 
 642     /** Called when the avatar actor is set/changes */
 643     //这是一个回调函数,当技能(能力,Ability)所关联的化身角色(Avatar Actor)被设置或者发生改变时,该函数会被调用。
 644     //化身角色通常代表玩家操控的角色或者游戏中的智能体,技能与化身角色紧密相连,角色的变化可能会影响技能的运行和表现,所以需要在角色改变时进行相应的处理。
 645     virtual void OnAvatarSet(const FGameplayAbilityActorInfo* ActorInfo, const FGameplayAbilitySpec& Spec);
 646 
 647     /** Takes in the ability spec and checks if we should allow replication on the ability spec, this will NOT stop replication of the ability UObject just the spec inside the UAbilitySystemComponenet ActivatableAbilities for this ability */
 648     //这个功能的核心是接收一个技能(能力)规格(Ability Spec),并检查是否应该允许该技能规格进行复制。
 649     //需要注意的是,这里的复制限制仅针对 UAbilitySystemComponent 中可激活技能列表(ActivatableAbilities)里的技能规格,而不是技能的 UObject 本身。
 650     //在多人游戏开发中,技能规格的复制是确保不同客户端和服务器之间技能状态同步的重要机制,但有时我们可能需要根据特定条件来控制某些技能规格是否进行复制。
 651     virtual bool ShouldReplicateAbilitySpec(const FGameplayAbilitySpec& AbilitySpec) const
 652     {
 653         return true;
 654     }
 655 
 656     /** 
 657      * Invalidates the current prediction key. This should be used in cases where there is a valid prediction window, but the server is doing logic that only it can do, and afterwards performs an action that the client could predict (had the client been able to run the server-only code prior).
 658      * This returns instantly and has no other side effects other than clearing the current prediction key.
 659      */
 660     //此功能的作用是使当前的预测键(Prediction Key)失效。
 661     //在多人游戏的网络同步机制里,预测键是一个重要的概念,用于客户端预测服务器端的行为,以减少玩家操作的延迟感。
 662     //但在某些特定情况下,服务器会执行只有它能进行的逻辑,执行完这些逻辑后又会进行一个客户端原本可以预测的操作。
 663     //此时就需要调用这个功能来使当前预测键失效,该操作会立即返回,并且除了清除当前预测键之外没有其他副作用。
 664     UFUNCTION(BlueprintCallable, Category = Ability)
 665     void InvalidateClientPredictionKey() const;
 666 
 667     /** Removes the GameplayEffect that granted this ability. Can only be called on instanced abilities. */
 668     //这个功能的作用是移除赋予当前技能(能力)的游戏效果(GameplayEffect),不过此操作仅允许在已实例化的技能上执行。
 669     //在游戏开发里,技能往往可以通过游戏效果来赋予角色,例如某个增益效果可能会临时让角色获得一个新技能。
 670     //当不再需要这个技能时,就可以使用该功能移除赋予此技能的游戏效果。
 671     UFUNCTION(BlueprintCallable, Category = Ability)
 672     virtual void RemoveGrantedByEffect();
 673 
 674     /** Adds a debug message to display to the user */
 675     //这个功能的主要目的是向用户添加并显示一条调试消息。在游戏开发或者其他应用程序开发过程中,调试消息是一种非常有用的工具,
 676     //它可以帮助开发者在程序运行时向用户展示一些关键信息,比如技能的状态、系统的错误提示、性能数据等,方便开发者和用户及时了解程序的运行情况,排查潜在问题。
 677     void AddAbilityTaskDebugMessage(UGameplayTask* AbilityTask, FString DebugMessage);
 678 
 679     // --------------------------------------
 680     //    Public variables, exposed for backwards compatibility
 681     // --------------------------------------
 682 
 683     /** This ability has these tags */
 684     //This ability has these tags
 685     //
 686     UE_DEPRECATED_FORGAME(5.5, "Use GetAssetTags(). This is being made non-mutable, private and renamed to AssetTags in the future. Use SetAssetTags to set defaults (in constructor only).")
 687     UPROPERTY(EditDefaultsOnly, Category = Tags, DisplayName="AssetTags (Default AbilityTags)", meta=(Categories="AbilityTagCategory"))
 688     FGameplayTagContainer AbilityTags;
 689 
 690     /** If true, this ability will always replicate input press/release events to the server. */
 691     //如果该值为 true,则此技能将始终把输入的按下 / 释放事件复制到服务器端。
 692     UPROPERTY(EditDefaultsOnly, Category = Input)
 693     bool bReplicateInputDirectly;
 694 
 695     /** Set when the remote instance of this ability has ended (but the local instance may still be running or finishing up */
 696     //当此技能的远程实例结束时进行设置(但本地实例可能仍在运行或正在收尾)。
 697     UPROPERTY()
 698     bool RemoteInstanceEnded;
 699 
 700     // --------------------------------------
 701     //    UObject overrides
 702     // --------------------------------------    
 703     virtual UWorld* GetWorld() const override;
 704     virtual int32 GetFunctionCallspace(UFunction* Function, FFrame* Stack) override;
 705     virtual bool CallRemoteFunction(UFunction* Function, void* Parameters, FOutParmRec* OutParms, FFrame* Stack) override;
 706     virtual bool IsSupportedForNetworking() const override;
 707 
 708 #if WITH_EDITOR
 709     virtual EDataValidationResult IsDataValid(FDataValidationContext& Context) const override;
 710 #endif
 711 
 712     /** Overridden to allow Blueprint replicated properties to work */
 713     //对其进行重写是为了让蓝图(Blueprint)的可复制属性能够正常工作。
 714     virtual void GetLifetimeReplicatedProps(TArray< class FLifetimeProperty >& OutLifetimeProps) const;
 715 
 716 #if UE_WITH_IRIS
 717     /** Register all replication fragments */
 718     //注册所有的复制片段。
 719     virtual void RegisterReplicationFragments(UE::Net::FFragmentRegistrationContext& Context, UE::Net::EFragmentRegistrationFlags RegistrationFlags) override;
 720 #endif // UE_WITH_IRIS
 721 
 722     // --------------------------------------
 723     //    IGameplayTaskOwnerInterface
 724     // --------------------------------------    
 725     virtual UGameplayTasksComponent* GetGameplayTasksComponent(const UGameplayTask& Task) const override;
 726     virtual AActor* GetGameplayTaskOwner(const UGameplayTask* Task) const override;
 727     virtual AActor* GetGameplayTaskAvatar(const UGameplayTask* Task) const override;
 728     virtual void OnGameplayTaskInitialized(UGameplayTask& Task) override;
 729     virtual void OnGameplayTaskActivated(UGameplayTask& Task) override;
 730     virtual void OnGameplayTaskDeactivated(UGameplayTask& Task) override;
 731 
 732 protected:
 733 
 734     /**
 735       * Allows a derived class to set the default GameplayTags that this Ability is considered to have (formerly AbilityTags).
 736      * This can only be called during construction.
 737      * At runtime, the AbilitySpec is queried through a Gameplay Ability's CDO for its AbilityTags which can be a combination of these
 738      * Asset Tags and specifically granted DynamicAbilityTags (all instances generated from an AbilitySpec are expected to share the same AbilityTags).
 739      */
 740      
 741      /**
 742       * 允许派生类设置此技能被视为具有的默认游戏玩法标签(以前称为技能标签)。
 743       * 此操作只能在构造过程中调用。
 744       * 在运行时,通过游戏玩法技能的默认对象类(CDO)查询技能规范(AbilitySpec),以获取其技能标签,这些标签可能是这些资产标签与专门授予的动态技能标签的组合
 745       * (预计从技能规范生成的所有实例都共享相同的技能标签)。
 746       */ 
 747     void SetAssetTags(const FGameplayTagContainer& InAbilityTags);
 748 
 749     // --------------------------------------
 750     //    ShouldAbilityRespondToEvent
 751     // --------------------------------------
 752 
 753     /** Returns true if this ability can be activated right now. Has no side effects */
 754     //如果该技能目前可以激活,则返回 true。此操作没有副作用。
 755     UFUNCTION(BlueprintImplementableEvent, Category = Ability, DisplayName = "ShouldAbilityRespondToEvent", meta=(ScriptName = "ShouldAbilityRespondToEvent"))
 756     bool K2_ShouldAbilityRespondToEvent(FGameplayAbilityActorInfo ActorInfo, FGameplayEventData Payload) const;
 757 
 758     bool bHasBlueprintShouldAbilityRespondToEvent;
 759 
 760     /** Sends a gameplay event, also creates a prediction window */
 761     //发送一个游戏玩法事件,同时创建一个预测窗口。
 762     //结合起来的作用
 763     //发送游戏玩法事件的同时创建预测窗口,意味着在触发某个游戏事件时,开启一个时间段来进行客户端的预测处理。
 764     //例如,当玩家释放技能时,客户端会立即发送技能释放的游戏玩法事件,并创建预测窗口,在窗口时间内本地模拟技能的效果(如动画播放、伤害计算等),
 765     //等待服务器的确认信息,以确保游戏状态在客户端和服务器之间的最终一致性。
 766     UFUNCTION(BlueprintCallable, Category = Ability)
 767     virtual void SendGameplayEvent(UPARAM(meta=(GameplayTagFilter="GameplayEventTagsCategory")) FGameplayTag EventTag, FGameplayEventData Payload);
 768 
 769     // --------------------------------------
 770     //    CanActivate
 771     // --------------------------------------
 772     
 773     /** Returns true if this ability can be activated right now. Has no side effects */
 774     //如果该技能目前可以激活,则返回 true,且此操作不会产生任何副作用。
 775     UFUNCTION(BlueprintImplementableEvent, Category = Ability, DisplayName="CanActivateAbility", meta=(ScriptName="CanActivateAbility"))
 776     bool K2_CanActivateAbility(FGameplayAbilityActorInfo ActorInfo, const FGameplayAbilitySpecHandle Handle, FGameplayTagContainer& RelevantTags) const;
 777 
 778     bool bHasBlueprintCanUse;
 779 
 780     // --------------------------------------
 781     //    ActivateAbility
 782     // --------------------------------------
 783 
 784     /**
 785      * The main function that defines what an ability does.
 786      *  -Child classes will want to override this
 787      *  -This function graph should call CommitAbility
 788      *  -This function graph should call EndAbility
 789      *  
 790      *  Latent/async actions are ok in this graph. Note that Commit and EndAbility calling requirements speak to the K2_ActivateAbility graph. 
 791      *  In C++, the call to K2_ActivateAbility() may return without CommitAbility or EndAbility having been called. But it is expected that this
 792      *  will only occur when latent/async actions are pending. When K2_ActivateAbility logically finishes, then we will expect Commit/End to have been called.
 793      *  
 794      */
 795 
 796     /**
 797      * 该函数是定义技能具体功能的主要函数。
 798      *  - 子类通常需要重写此函数
 799      *  - 此函数图表(蓝图中可理解为节点图)应调用“提交技能(CommitAbility)”函数
 800      *  - 此函数图表应调用“结束技能(EndAbility)”函数
 801      *
 802      *  此函数图表中允许使用延迟/异步操作。需要注意的是,“提交技能”和“结束技能”的调用要求是针对“K2_ActivateAbility”函数图表而言的。
 803      *  在 C++ 代码中,调用“K2_ActivateAbility()”函数时,可能在未调用“提交技能”或“结束技能”函数的情况下就返回了。
 804      *  但这通常只发生在存在延迟/异步操作未完成时。当“K2_ActivateAbility”逻辑上执行完毕后,我们期望“提交技能”和“结束技能”函数已经被调用。
 805      */
 806     //激活GA
 807     UFUNCTION(BlueprintImplementableEvent, Category = Ability, DisplayName = "ActivateAbility", meta=(ScriptName = "ActivateAbility"))
 808     void K2_ActivateAbility();
 809 
 810     UFUNCTION(BlueprintImplementableEvent, Category = Ability, DisplayName = "ActivateAbilityFromEvent", meta=(ScriptName = "ActivateAbilityFromEvent"))
 811     void K2_ActivateAbilityFromEvent(const FGameplayEventData& EventData);
 812 
 813     bool bHasBlueprintActivate;
 814     bool bHasBlueprintActivateFromEvent;
 815 
 816     /** Actually activate ability, do not call this directly */
 817     //实际激活技能,但请勿直接调用此方法。
 818     virtual void ActivateAbility(const FGameplayAbilitySpecHandle Handle, const FGameplayAbilityActorInfo* ActorInfo, const FGameplayAbilityActivationInfo ActivationInfo, const FGameplayEventData* TriggerEventData);
 819 
 820     /** Do boilerplate init stuff and then call ActivateAbility */
 821     //执行一些常规的初始化操作,然后调用 ActivateAbility 函数。
 822     virtual void PreActivate(const FGameplayAbilitySpecHandle Handle, const FGameplayAbilityActorInfo* ActorInfo, const FGameplayAbilityActivationInfo ActivationInfo, FOnGameplayAbilityEnded::FDelegate* OnGameplayAbilityEndedDelegate, const FGameplayEventData* TriggerEventData = nullptr);
 823 
 824     /** Executes PreActivate and ActivateAbility */
 825     //执行 PreActivate 和 ActivateAbility 方法。
 826     void CallActivateAbility(const FGameplayAbilitySpecHandle Handle, const FGameplayAbilityActorInfo* ActorInfo, const FGameplayAbilityActivationInfo ActivationInfo, FOnGameplayAbilityEnded::FDelegate* OnGameplayAbilityEndedDelegate = nullptr, const FGameplayEventData* TriggerEventData = nullptr);
 827 
 828     /** Called on a predictive ability when the server confirms its execution */
 829     //当服务器确认预测性技能的执行时,会调用此方法。
 830     virtual void ConfirmActivateSucceed();
 831 
 832     // -------------------------------------
 833     //    EndAbility
 834     // -------------------------------------
 835     /** Call from blueprints to forcibly end the ability without canceling it. This will replicate the end ability to the client or server which can interrupt tasks */
 836     //可从蓝图中调用此操作,以在不取消技能的情况下强制结束该技能。
 837     //这会将技能结束的信息复制到客户端或服务器,此操作可能会中断正在进行的任务。
 838     UFUNCTION(BlueprintCallable, Category = Ability, DisplayName="End Ability", meta=(ScriptName = "EndAbility"))
 839     virtual void K2_EndAbility();
 840 
 841     /** Call from blueprints to end the ability naturally. This will only end predicted abilities locally, allowing it end naturally on the client or server */
 842     //可以从蓝图中调用此操作,让技能自然结束。这只会在本地结束预测性技能,使技能在客户端或服务器上自然终止。
 843     UFUNCTION(BlueprintCallable, Category = Ability, DisplayName = "End Ability Locally", meta = (ScriptName = "EndAbilityLocally"))
 844     virtual void K2_EndAbilityLocally();
 845 
 846     /** Blueprint event, will be called if an ability ends normally or abnormally */
 847     //这是一个蓝图事件,当技能正常结束或异常结束时都会调用该事件。
 848     UFUNCTION(BlueprintImplementableEvent, Category = Ability, DisplayName = "OnEndAbility", meta=(ScriptName = "OnEndAbility"))
 849     void K2_OnEndAbility(bool bWasCancelled);
 850 
 851     /** Check if the ability can be ended */
 852     //检查该技能是否可以结束。
 853     bool IsEndAbilityValid(const FGameplayAbilitySpecHandle Handle, const FGameplayAbilityActorInfo* ActorInfo) const;
 854 
 855     /** Native function, called if an ability ends normally or abnormally. If bReplicate is set to true, try to replicate the ending to the client/server */
 856     //这是一个原生函数(通常指用 C++ 等编程语言实现的底层函数),当技能正常结束或异常结束时会调用该函数。
 857     //如果 bReplicate(可能是一个布尔类型的标志变量)被设置为 true,则尝试将技能结束的信息复制到客户端或服务器。
 858     virtual void EndAbility(const FGameplayAbilitySpecHandle Handle, const FGameplayAbilityActorInfo* ActorInfo, const FGameplayAbilityActivationInfo ActivationInfo, bool bReplicateEndAbility, bool bWasCancelled);
 859 
 860     // -------------------------------------
 861     //  Apply Gameplay effects to Self
 862     // -------------------------------------
 863 
 864     /** Apply a gameplay effect to the owner of this ability */
 865     //将一个游戏玩法效果(Gameplay Effect)应用到该技能(Gameplay Ability)的拥有者身上
 866     UFUNCTION(BlueprintCallable, Category = Ability, DisplayName="ApplyGameplayEffectToOwner", meta=(ScriptName="ApplyGameplayEffectToOwner"))
 867     FActiveGameplayEffectHandle BP_ApplyGameplayEffectToOwner(TSubclassOf<UGameplayEffect> GameplayEffectClass, int32 GameplayEffectLevel = 1, int32 Stacks = 1);
 868 
 869     /** Non blueprintcallable, safe to call on CDO/NonInstance abilities */
 870     //该方法不可通过蓝图调用,并且在类默认对象(CDO,Class Default Object)或非实例化技能上调用是安全的
 871     FActiveGameplayEffectHandle ApplyGameplayEffectToOwner(const FGameplayAbilitySpecHandle Handle, const FGameplayAbilityActorInfo* ActorInfo, const FGameplayAbilityActivationInfo ActivationInfo, const UGameplayEffect* GameplayEffect, float GameplayEffectLevel, int32 Stacks = 1) const;
 872 
 873     /** Apply a previously created gameplay effect spec to the owner of this ability */
 874     //这句话的意思是 “将之前创建好的游戏玩法效果规格(Gameplay Effect Spec)应用到该技能的拥有者身上”。
 875     //在虚幻引擎的游戏玩法能力系统(Gameplay Ability System,GAS)中,
 876     //游戏玩法效果规格(FGameplayEffectSpec)是对游戏玩法效果(UGameplayEffect)进行实例化和参数化后的对象,它包含了具体应用效果时所需的详细信息,如效果等级、目标、修正值等。
 877     //而技能(Gameplay Ability)通常有一个拥有者(比如某个角色),此操作就是要让这个拥有者受到已创建好的效果规格所定义的效果影响。
 878     UFUNCTION(BlueprintCallable, Category = Ability, DisplayName = "ApplyGameplayEffectSpecToOwner", meta=(ScriptName = "ApplyGameplayEffectSpecToOwner"))
 879     FActiveGameplayEffectHandle K2_ApplyGameplayEffectSpecToOwner(const FGameplayEffectSpecHandle EffectSpecHandle);
 880 
 881     FActiveGameplayEffectHandle ApplyGameplayEffectSpecToOwner(const FGameplayAbilitySpecHandle AbilityHandle, const FGameplayAbilityActorInfo* ActorInfo, const FGameplayAbilityActivationInfo ActivationInfo, const FGameplayEffectSpecHandle SpecHandle) const;
 882 
 883     // -------------------------------------
 884     //  Apply Gameplay effects to Target
 885     // -------------------------------------
 886 
 887     /** Apply a gameplay effect to a Target */
 888     //向目标应用GE
 889     UFUNCTION(BlueprintCallable, Category = Ability, DisplayName = "ApplyGameplayEffectToTarget", meta=(ScriptName = "ApplyGameplayEffectToTarget"))
 890     TArray<FActiveGameplayEffectHandle> BP_ApplyGameplayEffectToTarget(FGameplayAbilityTargetDataHandle TargetData, TSubclassOf<UGameplayEffect> GameplayEffectClass, int32 GameplayEffectLevel = 1, int32 Stacks = 1);
 891 
 892     /** Non blueprintcallable, safe to call on CDO/NonInstance abilities */
 893     //此方法不可在蓝图中调用,在类默认对象(CDO)或非实例化的游戏玩法技能上调用是安全的。
 894     TArray<FActiveGameplayEffectHandle> ApplyGameplayEffectToTarget(const FGameplayAbilitySpecHandle Handle, const FGameplayAbilityActorInfo* ActorInfo, const FGameplayAbilityActivationInfo ActivationInfo, const FGameplayAbilityTargetDataHandle& Target, TSubclassOf<UGameplayEffect> GameplayEffectClass, float GameplayEffectLevel, int32 Stacks = 1) const;
 895 
 896     /** Apply a previously created gameplay effect spec to a target */
 897     //将之前创建好的游戏玩法效果规格应用到一个目标上。
 898     //游戏玩法效果规格(Gameplay Effect Spec):在虚幻引擎的游戏玩法能力系统(Gameplay Ability System,GAS)中,
 899     //Gameplay Effect 用于定义各种游戏效果,如属性修改(增加生命值、提升攻击力)、状态施加(眩晕、中毒)等。
 900     //而 Gameplay Effect Spec(FGameplayEffectSpec)是对 Gameplay Effect 进行实例化和参数化后的对象,它包含了具体应用效果时所需的详细信息,像效果的等级、目标、修正值等。
 901     UFUNCTION(BlueprintCallable, Category = Ability, DisplayName = "ApplyGameplayEffectSpecToTarget", meta=(ScriptName = "ApplyGameplayEffectSpecToTarget"))
 902     TArray<FActiveGameplayEffectHandle> K2_ApplyGameplayEffectSpecToTarget(const FGameplayEffectSpecHandle EffectSpecHandle, FGameplayAbilityTargetDataHandle TargetData);
 903 
 904     TArray<FActiveGameplayEffectHandle> ApplyGameplayEffectSpecToTarget(const FGameplayAbilitySpecHandle AbilityHandle, const FGameplayAbilityActorInfo* ActorInfo, const FGameplayAbilityActivationInfo ActivationInfo, const FGameplayEffectSpecHandle SpecHandle, const FGameplayAbilityTargetDataHandle& TargetData) const;
 905 
 906     // -------------------------------------
 907     //  Remove Gameplay effects from Self
 908     // -------------------------------------
 909     
 910     /** Removes GameplayEffects from owner which match the given asset level tags */
 911     //这句话描述的功能是从技能的拥有者身上移除那些与给定的资产等级标签(Asset Level Tags)相匹配的游戏玩法效果(Gameplay Effects)。
 912     UFUNCTION(BlueprintCallable, Category = Ability, DisplayName="RemoveGameplayEffectFromOwnerWithAssetTags", meta=(ScriptName="RemoveGameplayEffectFromOwnerWithAssetTags"))
 913     void BP_RemoveGameplayEffectFromOwnerWithAssetTags(FGameplayTagContainer WithAssetTags, int32 StacksToRemove = -1);
 914 
 915     /** Removes GameplayEffects from owner which grant the given tags */
 916     //此功能是从技能拥有者身上移除那些能够授予指定标签的游戏玩法效果(Gameplay Effects)。在虚幻引擎的游戏玩法能力系统(Gameplay Ability System,GAS)里,
 917     //游戏玩法效果可附带标签,这些标签能用来表示特定的状态、属性或能力等。该操作会检查技能拥有者当前身上所有的游戏玩法效果,找出那些会授予给定标签的效果并将其移除。
 918     UFUNCTION(BlueprintCallable, Category = Ability, DisplayName="RemoveGameplayEffectFromOwnerWithGrantedTags", meta=(ScriptName="RemoveGameplayEffectFromOwnerWithGrantedTags"))
 919     void BP_RemoveGameplayEffectFromOwnerWithGrantedTags(FGameplayTagContainer WithGrantedTags, int32 StacksToRemove = -1);
 920 
 921     /** Removes GameplayEffect from owner that match the given handle */
 922     //该功能是从技能的拥有者身上移除与给定句柄(Handle)相匹配的游戏玩法效果(GameplayEffect)。
 923     //在虚幻引擎的游戏玩法能力系统(Gameplay Ability System,GAS)中,当一个 GameplayEffect 被应用到某个对象上时,系统会为其分配一个唯一的句柄,
 924     //通过这个句柄可以对该效果进行管理和操作,此操作就是利用句柄来精准移除特定的 GameplayEffect。
 925     UFUNCTION(BlueprintCallable, Category = Ability, DisplayName = "RemoveGameplayEffectFromOwnerWithHandle", meta=(ScriptName = "RemoveGameplayEffectFromOwnerWithHandle"))
 926     void BP_RemoveGameplayEffectFromOwnerWithHandle(FActiveGameplayEffectHandle Handle, int32 StacksToRemove = -1);
 927 
 928     // -------------------------------------
 929     //    GameplayCue
 930     //    Abilities can invoke GameplayCues without having to create GameplayEffects
 931     // -------------------------------------
 932 
 933     /** Invoke a gameplay cue on the ability owner */
 934     //指的是在技能所有者(通常是角色)上触发一个游戏玩法提示(gameplay cue)。
 935     UFUNCTION(BlueprintCallable, Category = Ability, meta=(GameplayTagFilter="GameplayCue"), DisplayName="Execute GameplayCue On Owner", meta=(ScriptName="ExecuteGameplayCue"))
 936     virtual void K2_ExecuteGameplayCue(FGameplayTag GameplayCueTag, FGameplayEffectContextHandle Context);
 937 
 938     /** Invoke a gameplay cue on the ability owner, with extra parameters */
 939     //在技能所有者上触发一个游戏玩法提示(gameplay cue),并且同时传递额外的参数。
 940     UFUNCTION(BlueprintCallable, Category = Ability, meta = (GameplayTagFilter = "GameplayCue"), DisplayName = "Execute GameplayCueWithParams On Owner", meta=(ScriptName = "ExecuteGameplayCueWithParams"))
 941     virtual void K2_ExecuteGameplayCueWithParams(FGameplayTag GameplayCueTag, const FGameplayCueParameters& GameplayCueParameters);
 942 
 943     /** Adds a persistent gameplay cue to the ability owner. Optionally will remove if ability ends */
 944     //该功能用于给技能的所有者添加一个持续的游戏玩法提示(Persistent Gameplay Cue)。并且可以选择在技能结束时移除这个提示。
 945     UFUNCTION(BlueprintCallable, Category = Ability, meta=(GameplayTagFilter="GameplayCue"), DisplayName="Add GameplayCue To Owner", meta=(ScriptName="AddGameplayCue"))
 946     virtual void K2_AddGameplayCue(FGameplayTag GameplayCueTag, FGameplayEffectContextHandle Context, bool bRemoveOnAbilityEnd = true);
 947 
 948     /** Adds a persistent gameplay cue to the ability owner. Optionally will remove if ability ends */
 949     //该功能用于给技能的所有者添加一个持续的游戏玩法提示(Persistent Gameplay Cue)。并且可以选择在技能结束时移除这个提示。
 950     UFUNCTION(BlueprintCallable, Category = Ability, meta = (GameplayTagFilter = "GameplayCue"), DisplayName = "Add GameplayCueWithParams To Owner", meta=(ScriptName = "AddGameplayCueWithParams"))
 951     virtual void K2_AddGameplayCueWithParams(FGameplayTag GameplayCueTag, const FGameplayCueParameters& GameplayCueParameter, bool bRemoveOnAbilityEnd = true);
 952 
 953     /** Removes a persistent gameplay cue from the ability owner */
 954     //此功能的目的是从技能的所有者(通常是游戏角色或实体)身上移除一个持续的游戏玩法提示(Persistent Gameplay Cue)。
 955     UFUNCTION(BlueprintCallable, Category = Ability, meta=(GameplayTagFilter="GameplayCue"), DisplayName="Remove GameplayCue From Owner", meta=(ScriptName="RemoveGameplayCue"))
 956     virtual void K2_RemoveGameplayCue(FGameplayTag GameplayCueTag);
 957 
 958     // -------------------------------------
 959     //    Protected properties
 960     // -------------------------------------
 961 
 962     /** How an ability replicates state/events to everyone on the network. Replication is not required for NetExecutionPolicy. */
 963     //
 964     UPROPERTY(EditDefaultsOnly, Category = Advanced)
 965     TEnumAsByte<EGameplayAbilityReplicationPolicy::Type> ReplicationPolicy;
 966 
 967     /** How the ability is instanced when executed. This limits what an ability can do in its implementation. */
 968     //
 969     UPROPERTY(EditDefaultsOnly, Category = Advanced)
 970     TEnumAsByte<EGameplayAbilityInstancingPolicy::Type>    InstancingPolicy;
 971 
 972     /** If this is set, the server-side version of the ability can be canceled by the client-side version. The client-side version can always be canceled by the server. */
 973     //此功能定义了技能在客户端和服务器端的取消规则。当某个特定设置开启时,客户端版本的技能可以取消服务器端版本的技能,
 974     //不过无论如何,服务器端始终拥有取消客户端版本技能的权限。在多人游戏开发里,技能的取消操作管理对于维护游戏的一致性和公平性至关重要。
 975     UPROPERTY(EditDefaultsOnly, Category = Advanced)
 976     bool bServerRespectsRemoteAbilityCancellation;
 977 
 978     /** if true, and trying to activate an already active instanced ability, end it and re-trigger it. */
 979     //当此设置为 true 时,如果尝试激活一个已经处于激活状态的实例化技能(instanced ability),
 980     //系统会先结束该技能,然后重新触发它。在游戏开发中,技能系统里的实例化技能是指那些会被创建具体实例来运行的技能,
 981     //每个实例可能有自己独立的状态和属性。这个功能提供了一种处理重复激活已激活技能的方式,有助于实现一些特定的游戏逻辑。
 982     UPROPERTY(EditDefaultsOnly, Category = Advanced)
 983     bool bRetriggerInstancedAbility;
 984 
 985     /** This is information specific to this instance of the ability. E.g, whether it is predicting, authoring, confirmed, etc. */
 986     //这里所提及的内容是关于技能实例的特定信息。在游戏开发里,技能(能力,Ability)通常会被实例化以应用于具体的角色或情境中。
 987     //每个技能实例都可能有其独特的状态和属性,而这些信息可以用来描述该技能实例当前所处的状态,例如是否正在进行预测、是否拥有执行权限、是否已被确认等。
 988     UPROPERTY(BlueprintReadOnly, Category = Ability)
 989     FGameplayAbilityActivationInfo    CurrentActivationInfo;
 990 
 991     /** Information specific to this instance of the ability, if it was activated by an event */
 992     //当一个技能实例通过事件被激活时,会存在与该实例相关的特定信息。
 993     //这些信息对于精确管理和处理技能实例至关重要,能够帮助开发者了解技能激活的具体情境、
 994     //控制技能的执行过程以及与其他游戏系统进行交互。
 995     UPROPERTY(BlueprintReadOnly, Category = Ability)
 996     FGameplayEventData CurrentEventData;
 997 
 998     /** How does an ability execute on the network. Does a client "ask and predict", "ask and wait", "don't ask (just do it)". */
 999     //GA在网络上的行为
1000     UPROPERTY(EditDefaultsOnly, Category=Advanced)
1001     TEnumAsByte<EGameplayAbilityNetExecutionPolicy::Type> NetExecutionPolicy;
1002 
1003     /** What protections does this ability have? Should the client be allowed to request changes to the execution of the ability? */
1004     //GA的保护行为
1005     UPROPERTY(EditDefaultsOnly, Category = Advanced)
1006     TEnumAsByte<EGameplayAbilityNetSecurityPolicy::Type> NetSecurityPolicy;
1007 
1008     /** This GameplayEffect represents the cost (mana, stamina, etc) of the ability. It will be applied when the ability is committed. */
1009     //此描述表明在游戏开发中,存在一个游戏玩法效果(GameplayEffect)专门用于代表技能(Ability)的消耗,
1010     //这些消耗可以是魔法值(mana)、耐力值(stamina)等。当技能被确认执行时,这个游戏玩法效果就会被应用,从而扣除相应的资源。
1011     UPROPERTY(EditDefaultsOnly, Category = Costs)
1012     TSubclassOf<class UGameplayEffect> CostGameplayEffectClass;
1013 
1014     /** Triggers to determine if this ability should execute in response to an event */
1015     //这句话描述的是用于判断某个技能(能力,Ability)是否应该响应某个事件而执行的触发条件。
1016     //在游戏开发里,技能的执行通常不是随意的,而是需要满足特定的条件。这些触发条件就像是一个 “开关”,当特定事件发生且满足相应条件时,技能才会被触发执行。
1017     UPROPERTY(EditDefaultsOnly, Category = Triggers)
1018     TArray<FAbilityTriggerData> AbilityTriggers;
1019             
1020     /** This GameplayEffect represents the cooldown. It will be applied when the ability is committed and the ability cannot be used again until it is expired. */
1021     //在游戏开发里,此描述所涉及的游戏玩法效果(GameplayEffect)专门用于代表技能的冷却机制。当技能被确认执行(committed)时,这个代表冷却的游戏玩法效果就会被应用。
1022     //在冷却效果未结束(expired)之前,该技能无法再次被使用。冷却机制是游戏中平衡技能使用频率的重要手段,它可以避免玩家无限制地频繁使用强力技能,从而保证游戏的平衡性和策略性。
1023     UPROPERTY(EditDefaultsOnly, Category = Cooldowns)
1024     TSubclassOf<class UGameplayEffect> CooldownGameplayEffectClass;
1025 
1026     // ----------------------------------------------------------------------------------------------------------------
1027     //    Ability exclusion / canceling
1028     //  需要block/取消的TAGS
1029     // ----------------------------------------------------------------------------------------------------------------
1030 
1031     /** Abilities with these tags are cancelled when this ability is executed */
1032     //
1033     UPROPERTY(EditDefaultsOnly, Category = Tags, meta=(Categories="AbilityTagCategory"))
1034     FGameplayTagContainer CancelAbilitiesWithTag;
1035 
1036     /** Abilities with these tags are blocked while this ability is active */
1037     UPROPERTY(EditDefaultsOnly, Category = Tags, meta=(Categories="AbilityTagCategory"))
1038     FGameplayTagContainer BlockAbilitiesWithTag;
1039 
1040     /** Tags to apply to activating owner while this ability is active. These are replicated if ReplicateActivationOwnedTags is enabled in AbilitySystemGlobals. */
1041     UPROPERTY(EditDefaultsOnly, Category = Tags, meta=(Categories="OwnedTagsCategory"))
1042     FGameplayTagContainer ActivationOwnedTags;
1043 
1044     /** This ability can only be activated if the activating actor/component has all of these tags */
1045     UPROPERTY(EditDefaultsOnly, Category = Tags, meta=(Categories="OwnedTagsCategory"))
1046     FGameplayTagContainer ActivationRequiredTags;
1047 
1048     /** This ability is blocked if the activating actor/component has any of these tags */
1049     UPROPERTY(EditDefaultsOnly, Category = Tags, meta=(Categories="OwnedTagsCategory"))
1050     FGameplayTagContainer ActivationBlockedTags;
1051 
1052     /** This ability can only be activated if the source actor/component has all of these tags */
1053     UPROPERTY(EditDefaultsOnly, Category = Tags, meta=(Categories="SourceTagsCategory"))
1054     FGameplayTagContainer SourceRequiredTags;
1055 
1056     /** This ability is blocked if the source actor/component has any of these tags */
1057     UPROPERTY(EditDefaultsOnly, Category = Tags, meta=(Categories="SourceTagsCategory"))
1058     FGameplayTagContainer SourceBlockedTags;
1059 
1060     /** This ability can only be activated if the target actor/component has all of these tags */
1061     UPROPERTY(EditDefaultsOnly, Category = Tags, meta=(Categories="TargetTagsCategory"))
1062     FGameplayTagContainer TargetRequiredTags;
1063 
1064     /** This ability is blocked if the target actor/component has any of these tags */
1065     UPROPERTY(EditDefaultsOnly, Category = Tags, meta=(Categories="TargetTagsCategory"))
1066     FGameplayTagContainer TargetBlockedTags;
1067 
1068     // ----------------------------------------------------------------------------------------------------------------
1069     //    Ability Tasks
1070     // ----------------------------------------------------------------------------------------------------------------
1071 
1072     /** Finds all currently active tasks named InstanceName and confirms them. What this means depends on the individual task. By default, this does nothing other than ending if bEndTask is true. */
1073     //此功能用于查找所有当前处于活动状态且名称为 InstanceName 的任务,然后对这些任务进行确认操作。
1074     //不过,“确认” 这个操作具体意味着什么,会因每个任务的不同而有所差异。默认情况下,如果 bEndTask 参数为 true,则该功能除了结束任务之外,不会执行其他额外的操作。
1075     UFUNCTION(BlueprintCallable, Category = Ability)
1076     void ConfirmTaskByInstanceName(FName InstanceName, bool bEndTask);
1077 
1078     /** Internal function, cancels all the tasks we asked to cancel last frame (by instance name). */
1079     //这是一个内部函数,其主要作用是取消上一帧中通过实例名称指定要取消的所有任务。在游戏或复杂程序运行过程中,任务管理是一个重要的环节,有时候需要根据特定条件或用户操作来取消某些任务。
1080     //这个函数就是为了处理这种需求,它会按照之前记录的要取消的任务的实例名称,在当前操作中把这些任务取消掉。
1081     void EndOrCancelTasksByInstanceName();
1082     TArray<FName> CancelTaskInstanceNames;
1083 
1084     /** Add any task with this instance name to a list to be ended (not canceled) next frame.  See also CancelTaskByInstanceName. */
1085     //此功能的作用是将所有具有指定实例名称的任务添加到一个列表中,这些任务会在下一帧被结束(而不是取消)。同时还提到可以参考 CancelTaskByInstanceName 函数,
1086     //这表明二者可能在任务管理方面存在关联,但处理方式有所不同。在游戏开发或者复杂程序运行中,任务管理是一个关键环节,合理地结束或取消任务对于系统的稳定性和性能优化至关重要。
1087     UFUNCTION(BlueprintCallable, Category = Ability)
1088     void EndTaskByInstanceName(FName InstanceName);
1089     TArray<FName> EndTaskInstanceNames;
1090 
1091     /** Add any task with this instance name to a list to be canceled (not ended) next frame.  See also EndTaskByInstanceName. */
1092     //此功能主要用于管理游戏或程序中的任务。它会把所有具有指定实例名称的任务添加到一个列表里,这些任务会在下一帧被取消(而非结束)。
1093     //同时还提及可参考 EndTaskByInstanceName 函数,意味着这两个函数在任务管理方面有不同的作用,分别负责任务的取消和结束操作。
1094     UFUNCTION(BlueprintCallable, Category = Ability)
1095     void CancelTaskByInstanceName(FName InstanceName);
1096 
1097     /** Ends any active ability state task with the given name. If name is 'None' all active states will be ended (in an arbitrary order). */
1098     //这个功能的作用是结束具有指定名称的所有正在活跃的技能状态任务。若指定的名称为 “None”,则会以任意顺序结束所有活跃的技能状态任务。
1099     //在游戏开发里,技能状态任务通常是一些持续性的操作,比如技能的持续伤害效果、技能的增益状态等。结束这些任务意味着停止它们的运行,并进行必要的清理工作。
1100     UFUNCTION(BlueprintCallable, Category = Ability)
1101     void EndAbilityState(FName OptionalStateNameToEnd);
1102 
1103     /** List of currently active tasks, do not modify directly */
1104     //这里提到的是一个当前活跃任务的列表,并且明确提示不要直接对其进行修改。
1105     //在游戏开发或其他复杂的程序系统中,任务管理是很重要的一部分,这个列表记录了当前正在运行的任务。
1106     //之所以不建议直接修改,是为了保证系统的稳定性和数据的一致性,避免因不当修改引发各种问题。
1107     UPROPERTY()
1108     TArray<TObjectPtr<UGameplayTask>>    ActiveTasks;
1109 
1110     /** Tasks can emit debug messages throughout their life for debugging purposes. Saved on the ability so that they persist after task is finished */
1111     //在软件开发尤其是游戏开发的技能系统里,任务(Tasks)在其整个生命周期内能够发出调试信息,这些信息的主要用途是辅助开发者进行调试工作。
1112     //并且,这些调试信息会被保存到技能(Ability)中,从而保证在任务结束之后,这些信息依然能够被保留下来,方便开发者后续查看和分析。
1113     TArray<FAbilityTaskDebugMessage> TaskDebugMessages;
1114 
1115     // ----------------------------------------------------------------------------------------------------------------
1116     //    Animation
1117     // ----------------------------------------------------------------------------------------------------------------
1118 
1119     /** Immediately jumps the active montage to a section */
1120     //该功能的作用是立即将正在播放的蒙太奇(Montage)跳转到指定的片段(Section)。
1121     UFUNCTION(BlueprintCallable, Category="Ability|Animation")
1122     void MontageJumpToSection(FName SectionName);
1123 
1124     /** Sets pending section on active montage */
1125     //“Sets pending section on active montage” 指的是在当前正在播放的动画蒙太奇(Animation Montage)里设置一个待执行的片段(Section)。
1126     UFUNCTION(BlueprintCallable, Category = "Ability|Animation")
1127     void MontageSetNextSectionName(FName FromSectionName, FName ToSectionName);
1128 
1129     /**
1130      * Stops the current animation montage.
1131      *停止当前正在播放的蒙太奇
1132      * @param OverrideBlendTime If >= 0, will override the BlendOutTime parameter on the AnimMontage instance
1133      */
1134     UFUNCTION(BlueprintCallable, Category="Ability|Animation", Meta = (AdvancedDisplay = "OverrideBlendOutTime"))
1135     void MontageStop(float OverrideBlendOutTime = -1.0f);
1136 
1137     /** Active montage being played by this ability */
1138     //描述的是由当前技能(ability)正在播放的活动动画蒙太奇(active montage)。
1139     UPROPERTY()
1140     TObjectPtr<class UAnimMontage> CurrentMontage;
1141 
1142     // ----------------------------------------------------------------------------------------------------------------
1143     //    Target Data
1144     //**********************************很重要*************************************
1145     // ----------------------------------------------------------------------------------------------------------------
1146 
1147     /** Creates a target location from where the owner avatar is */
1148     //这句话描述的功能是基于技能所有者的化身(avatar,通常指游戏中代表玩家或角色的形象)当前所处的位置来创建一个目标位置。
1149     UFUNCTION(BlueprintPure, Category = Ability)
1150     FGameplayAbilityTargetingLocationInfo MakeTargetLocationInfoFromOwnerActor();
1151 
1152     /** Creates a target location from a socket on the owner avatar's skeletal mesh */
1153     //此功能是从技能所有者化身的骨骼网格体(skeletal mesh)上的一个套接字(socket)来创建目标位置。
1154     UFUNCTION(BlueprintPure, Category = Ability)
1155     FGameplayAbilityTargetingLocationInfo MakeTargetLocationInfoFromOwnerSkeletalMeshComponent(FName SocketName);
1156 
1157     // ----------------------------------------------------------------------------------------------------------------
1158     //    Setters for temporary execution data
1159     // ----------------------------------------------------------------------------------------------------------------
1160 
1161     /** Called to initialize after being created due to replication */
1162     //这句话描述的是在对象由于网络复制(replication)而被创建之后,调用特定的初始化函数来进行初始化操作。
1163     virtual void PostNetInit();
1164 
1165     /** Modifies actor info, only safe on instanced abilities */
1166     //此描述表明存在对角色信息(actor info)进行修改的操作,不过强调了该操作仅在实例化的技能(instanced abilities)情境下是安全的。
1167     virtual void SetCurrentActorInfo(const FGameplayAbilitySpecHandle Handle, const FGameplayAbilityActorInfo* ActorInfo) const;
1168     
1169     /** Modifies activation info, only safe on instanced abilities */
1170     //此功能是对技能激活信息(Activation Info)进行修改,但特别强调该操作仅在实例化技能(Instanced Abilities)的情况下是安全的。
1171     virtual void SetCurrentActivationInfo(const FGameplayAbilityActivationInfo ActivationInfo);
1172     
1173     /** Sets both actor and activation info */
1174     //设置角色信息(actor info)和技能激活信息(activation info)。
1175     void SetCurrentInfo(const FGameplayAbilitySpecHandle Handle, const FGameplayAbilityActorInfo* ActorInfo, const FGameplayAbilityActivationInfo ActivationInfo);
1176     
1177     /** 
1178      *  This is shared, cached information about the thing using us
1179      *     E.g, Actor*, MovementComponent*, AnimInstance, etc.
1180      *     This is hopefully allocated once per actor and shared by many abilities.
1181      *     The actual struct may be overridden per game to include game specific data.
1182      *     (E.g, child classes may want to cast to FMyGameAbilityActorInfo)
1183      */
1184 
1185     /**
1186     这是关于使用我们(此技能)的对象的共享、缓存信息。
1187     例如,角色指针、移动组件指针、动画实例等。
1188     希望这个信息针对每个角色只分配一次,并由多个技能共享。
1189     实际的结构体可以在每个游戏中进行重写,以包含特定游戏的数据。
1190     (例如,子类可能希望将其转换为 FMyGameAbilityActorInfo 类型)
1191     */
1192 
1193     //当前角色
1194     mutable const FGameplayAbilityActorInfo* CurrentActorInfo;
1195 
1196     /** For instanced abilities */
1197     //对于实例化技能  实例化技能只能通过当前句柄
1198     mutable FGameplayAbilitySpecHandle CurrentSpecHandle;
1199 
1200     /** GameplayCues that were added during this ability that will get automatically removed when it ends */
1201     //在该技能使用期间添加的游戏玩法提示(Gameplay Cues),会在技能结束时自动移除。
1202     TSet<FGameplayTag> TrackedGameplayCues;
1203 
1204     /** True if the ability is currently active. For instance per owner abilities */
1205     //如果该技能当前处于激活状态,则返回 true。这适用于每个所有者(通常指技能使用者,如游戏角色)的技能情况。
1206     UPROPERTY()
1207     bool bIsActive;
1208     
1209     /** True if the end ability has been called, but has not yet completed. */
1210     //如果已经调用了结束技能的操作,但技能尚未完成结束流程,则返回 true。
1211     UPROPERTY()
1212     bool bIsAbilityEnding = false;
1213 
1214     /** True if the ability is currently cancelable, if not will only be canceled by hard EndAbility calls */
1215     //如果该技能当前可被取消,则返回 true;若不可取消,则只能通过强制调用结束技能的方法(EndAbility)来取消。
1216     UPROPERTY()
1217     bool bIsCancelable;
1218 
1219     /** True if the ability block flags are currently enabled */
1220     //如果当前技能的阻塞标志已启用,则返回 true
1221     UPROPERTY()
1222     bool bIsBlockingOtherAbilities;
1223 
1224     /** A count of all the current scope locks. */
1225     //当前所有作用域锁的数量统计。
1226     mutable int8 ScopeLockCount;
1227 
1228     /** A list of all the functions waiting for the scope lock to end so they can run. */
1229     //这句话描述的是一个等待队列,其中存放着所有等待某个作用域锁(Scope Lock)释放,进而得以运行的函数。
1230     mutable TArray<FPostLockDelegate> WaitingToExecute;
1231 
1232     /** Increases the scope lock count. */
1233     //增加作用域锁
1234     void IncrementListLock() const;
1235 
1236     /** Decreases the scope lock count. Runs the waiting to execute delegates if the count drops to zero. */
1237     //这段描述涉及到作用域锁(Scope Lock)的管理逻辑。具体来说,它做了两件事:
1238     //一是减少作用域锁的计数,二是当计数降为 0 时,运行那些等待执行的委托(delegates)。
1239     void DecrementListLock() const;
1240 
1241 public:
1242     //请无视
1243     UE_DEPRECATED(5.4, "This is unsafe and unnecessary.  It is ignored.")
1244     void SetMarkPendingKillOnAbilityEnd(bool bInMarkPendingKillOnAbilityEnd) {}
1245 
1246     //请无视
1247     UE_DEPRECATED(5.4, "This is unsafe and unnecessary.  It will always return false.")
1248     bool IsMarkPendingKillOnAbilityEnd() const { return false; }
1249 
1250 protected:
1251 
1252     /** Flag that is set by AbilitySystemComponent::OnRemoveAbility to indicate the ability needs to be cleaned up in AbilitySystemComponent::NotifyAbilityEnded */
1253     UE_DEPRECATED(5.4, "This is unsafe. Do not use.")
1254     UPROPERTY(BlueprintReadOnly, Category = Ability, meta=(DeprecatedProperty, DeprecationMessage="This is unsafe. Do not use."))
1255     bool bMarkPendingKillOnAbilityEnd;
1256 };
完整的代码段

------based on UE5.5.2

 

 

posted @ 2025-02-18 00:17  mcwhirr  阅读(233)  评论(0)    收藏  举报