GAS概述

内容来自UE GAS官方文档。

犯了个错误,一开始就去看了GAS详细文档,了解任何一样东西,先理解整体总是最好的。

现在先从UE官方文档看一个大概。

Gameplay Ability: 可以是c++或者蓝图类,定义了Ability的结构以及replication和实例化行为。

Ability Tasks: 写在c++中,经常性在执行完后调用相关delegate,例如可能与cancel GA有关。

Gameplay Atttributes: 属性,如生命值

Gameplay Effects: 更像是各种buff和debuff

Ability System Component: Any Actor that interacts with the Gameplay Ability System must have an Ability System Component。This Component will activate Abilities, store Attributes, update Effects, and handle interactions between Actors

GameplayAbility(GA)

下面是几个在ASC中的函数

grantability

  • GiveAbility: Specifies the Ability to add with an FGameplayAbilitySpec, and returns an FGameplayAbilitySpecHandle.

  • GiveAbilityAndActivateOnce: Specifies the Ability to add with an FGameplayAbilitySpec, and returns an FGameplayAbilitySpecHandle. The Ability must be instanced and able to run on the server. After attempting to run the Ability on the server, a FGameplayAbilitySpecHandle will be returned. If the Ability did not meet the required criteria, or if it could not execute, the return value will be invalid and the Ability System Component will not be granted the Ability.

revoke abiliy, 通过FGameplayAbilitySpecHandle

  • ClearAbility: Removes the specified Ability from the Ability System Component.

  • SetRemoveAbilityOnEnd: Removes the specified Ability from the Ability System Component when that ability is finished executing. If the Ability is not executing, it will be removed immediately. If the Ability is executing, its input will be cleared immediately so that the player cannot reactivate or interact with it any further.

  • ClearAllAbilities: Removes all Abilities from the Ability System Component. This function is the only one that does not require an FGameplayAbilitySpecHandle.

基本使用

CanActivateAbility: 是否能使用,例如测试如果技能不能使用,设置icon为灰色。

CallActivateAbility:关于使用Ability,经常先CanActivateAbility之后用这个 

主要需要覆写的函数是ActivateAbility, 

CommitAbility:用来apply the cost of executing the ability. 例如扣蓝。

CancelAbility:provides a mechanism to cancel the Ability, although the Ability's CanBeCanceled function can reject the request。和CommitAbility不同,this function is available for callers outside of the Ability itself。

TryActivateAbility: CanActivateAbility + CallActivateAbility

EndAbility:Ability结束或者cancel可自动调用。若EndAbiilty没有成功调用,系统会认为改Ability会一直再跑,例如喝药水,如果没有没有成功调用这个,这个ability就会block其他的GA比如不能爬楼梯等等。

Tags

Tags可以帮助GA怎样其他GA交互。

Each Ability possesses a set of Tags that identify and categorize it in ways that can affect its behavior, as well as Gameplay Tag Containers and Gameplay Tag Queries to support these interactions with other Abilities.

Cancel Abilities With Tag: 取消正在executing的ability,如果match the list provided

Block Abilities With Tag: Prevents execution of any other Ability with a matching Tag while this Ability is executing.

Activation Owned Tags: While this Ability is executing, the owner of the Ability will be granted this set of Tags.

Activation Required Tags: The Ability can only be activated if the activating Actor or Component has all of these Tags.

Activation Blocked Tags: The Ability can only be activated if the activating Actor or Component does not have any of these Tags.

Target Required Tags: The Ability can only be activated if the targeted Actor or Component has all of these Tags.

Target Blocked Tags: The Ability can only be activated if the targeted Actor or Component does not have any of these Tags.

Replication

Ability's Gameplay Ability Replication Policy

Local Predicted: 

This option provides a good balance of responsiveness and accuracy. 

Local Only:

The client simply runs the Ability locally.

Server Initiated:

 Abilities that initiate on the server will propagate to clients. These are often more accurate.

but the client using the Ability will observe a delay due to the lack of local prediction.

Server Only:

"Server Only" Abilities will run on the server, and will not replicate to clients. But any variables these Abilities change will replicate as they normally do.In this way, the Ability can still have effects that clients observe, even though the Ability itself will only run on the server.

Instancing Policy

通常来说,当一个技能执行时,一个新的Object会生成,可能只存在非常短暂的时间,如果在一个很多人的网络游戏中,对性能会产生影响。为了提供一种性能和功能的平衡。提供了三种实例化的类型。

Instanced per Execution:  A copy of the Ability's Object will spawn each time the Ability runs。the simplest instancing policy to implement。适合不经常运行的Ability,例如大招~

Instanced per Actor: Each Actor will spawn one instance of this Ability when the Ability is first executed, and future executions will reuse it。虽然需要去清理成员变量,但是也提供了在不同次执行之间的信息。Per-Actor is ideal for replication, as the Ability has a replicated Object that can handle variable changes and RPCs, but does not waste network bandwidth and CPU time spawning a new Object every time it runs。在大范围的场景中较为适用。

Non-Instanced: This is the most efficient instancing policy in all categories。The Ability will not spawn any Object when it runs, and will instead use the Class Default Object。有多个限制。1. this policy uniquely requires that the Ability is written entirely in C++ 2.the Ability must not change member variables or bind Delegates during its execution of the Ability 3. The Ability also cannot replicate variables or handle RPCs所以这一类只能用在不需要在Ability内部存储变量且不需要replicate any data. 非常适合执行频繁且被很多character使用,例如大型RTS或者MOBA中角色的基本攻击。

Triggering with Gameplay Events

The usual way to do this is by calling Send Gameplay Event To Actor and providing an Actor that implements the IAbilitySystemInterface interface and the contextual information that Gameplay Events require.

 it is also possible to call Handle Gameplay Event directly on an Ability System Component.Because this isn't the normal path to calling Gameplay Abilities, context information that the Ability may need will be passed in through the FGameplayEventData data structure.This structure is generic and will not be extended for any specific Gameplay Event or Ability, but should be sufficient for any use case. The polymorphic ContextHandle field will provide support for additional information as needed.

once implemented in your Gameplay Ability's Blueprint, Activate Ability From Event will replace Activate Ability, taking all activation traffic through itself.

Gameplay Attributes and Gameplay Effects

Actors与GAS之间需要通过一些数值交互,并让Ability影响到gameplay,Gameplay Attributes。并且GA是通过GE来修改的。

 Attributes are declared as UProperties of FGameplayAttribute type within Attribute Sets, which both contain Attributes and supervise any attempts to modify them.

Attributes and Attribute Sets must be created in native code - they cannot be created in Blueprints.

Creating an Attribute Set

UCLASS()
class USimpleAttributeSet : public UAttributeSet
{
    GENERATED_BODY()
public:
    /** Set default values. For example, Health should be set to a positive number */
    USimpleAttributeSet();
    /** This measures how much damage can be absorbed before dying. */
    UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Attributes")
    FGameplayAttributeData Health;
};

Attribute Set需要注册到ASC中,可以直接在ASC中设置owning actor, 或者传到ASC的GetOrCreateAttributeSubobject()

Gameplay Effects

Gameplay Effects are the Gameplay Ability System's way to change Attributes. This includes:

  • Direct changes to the Attribute's base value, like taking away health points from an Actor that has received damage.

  • Temporary changes (often called "buffs" or "debuffs"), like granting a boost to movement speed for a few seconds.

  • Persistent changes that are applied over time, like regenerating a certain amount of magic points per second over a period of several seconds (or indefinitely).

Gameplay Effects are implemented as data-only Blueprints (of base class UGameplayEffect) that interact with the Ability System Component and can be stored there while they are active, if appropriate.

Major Properties of GE

Duration: 持续时间

Modifiers and Executions: Modifiers determine how the Gameplay Effect interacts with Attributes. This includes mathematical interactions with Attributes themselves, like "increase armor rating by 5 percent" as well as Gameplay Tag requirements to execute the Effect. 当modifiers需要更多的功能支持可以是哟个executions, Executions use the UGameplayEffectExecutionCalculation to define custom behaviors that the Gameplay Effect will have when it executes.Executions use the UGameplayEffectExecutionCalculation to define custom behaviors that the Gameplay Effect will have when it executes.适合于一些复杂的修改公式。

Application Requirements: Application Requirements include sets of Gameplay Tags that are required (or forbidden) to be present in order for a Gameplay Effect to apply,and a random chance for a Gameplay Effect not to apply。

Granted Abilities: Gameplay Effects can grant Abilities, not just Gameplay Tags, when they apply。例如,如果一个人被含有有火属性相关的effect攻击时,如果自身含有tag或者attribute显示自己被油浸润,就会产生着火的ability.之后会有一段持续时间的特效。

Stacking: "Stacking" refers to the policy of applying a buff or debuff(or Gameplay Effect, in this case) to a target that already carries it。The system supports a wide variety of Stacking behaviors, such as building up until a threshold is broken, maintaining a "stack count" that increases with each fresh application up to a maximum limit, resetting or appending time on a limited-time Effect, or simply applying multiple instances of the Effect independently with individual timers.

Gameplay Cue Display:  Gameplay Cues are a network-efficent way to manage cosmetic effects。Gameplay Abilities and Gameplay Effects can trigger them。

All Gameplay Cues must be associated with a Gameplay Tag that start with "GameplayCue", such as "GameplayCue.ElectricalSparks" or "GameplayCue.WaterSplash.Big".

The Gameplay Cue Manager executes Gameplay Cues. Actors can respond to Gameplay Cues by implementing the IGameplayCueInterface and having a function whose name matches the Gameplay Cue's tag. Standalone Gameplay Cue Notify Blueprints can also respond to Gameplay Cues.

Programming Effect and Attribute Interaction

当一个GE修改Attributes时有几个函数可以覆写来控制。例如,当health等于0的时候,不能再减少了。AttributeSet可以通过覆写几个函数,来控制其中的任何一个Attribute. 

 

Ability Tasks

Ability Tasks (C++ class UAbilityTask) are a specialized form of the more general Gameplay Task class intended to work with Gameplay Abilities。

GAS中通常含有多个AbilityTask, They perform asynchronous work during a Gameplay Ability's execution, and have the capability to affect execution flow by calling Delegates (in native C++ code) or moving through one or more output execution pins (in Blueprints). This enables Abilities to execute across multiple frames, and to perform several distinct functions in the same frame. Most Ability Tasks have an execution pin that fires immediately, enabling Blueprint execution to continue after starting a Task. In addition, there are often task-specific pins that will fire after a delay, or following a certain event that may or may not happen.

Ability Tasks can self-terminate by calling the EndTask function, or it can wait to be terminated automatically when the Gameplay Ability that ran it ends.

Ability Task > GA

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值