BlueRose
文章97
标签28
分类7
GameplayTag、Event与GameplayCue

GameplayTag、Event与GameplayCue

简述

GameplayAbility框架使用GameplayTag作为各种状态判断的依据,甚至使用它作为Event进行传递。

以下是actionRPG的标签设计:

Ability(能力类型:使用物品、连击、随机数值技能、技能)
|——item
|——Melee
|——Ranged
|——Skill
|   └──GA_PlayerSkillMeteorStorm
Cooldown(技能冷却:存在即代表技能处于冷却状态)
|   └──Skill
EffectContainer
|   └──Default
Event(事件)
|   └──Montage 
|        |——layer
|        |   |——Combo
|        |   |——BurstPound
|        |   |——ChestKick
|        |   |——FrontalAttack
|        |   |——GroundPound
|        |   └──JumpSlam
|        └──Shared
|            |——UseItem
|            |——UseSkill
|            └──WeaponHit
Status(状态)
    └──DamageImmune

简单用法

在编辑-项目设置-GameplayTags选项卡中可以编辑标签。

具体使用方法可以参考:
https://www.unrealengine.com/zh-CN/tech-blog/using-gameplay-tags-to-label-and-organize-your-content-in-ue4?lang=zh-CN

相关的Tasks类

UAbilityTask_WaitGameplayEvent与UAbilityTask_WaitGameplayTagAdded。配合SendGameplayEventToActor函数可以实现防反之类的效果。

SendGameplayEventToActor的用法可以参考actionRPG项目,在WeaponActor中(位于Content/Blueprint/Weapon/),它的ActorBeginOverlap事件用于实现武器攻击效果。其中它会执行SendGameplayEventToActor函数,给所有有效对象(带有GameplayAbilityComponent)添加事件标签。

GameplayCue

介绍:
https://docs.unrealengine.com/en-US/Gameplay/GameplayAbilitySystem/GameplayAttributesAndGameplayEffects/index.html

位于:窗口—GameplayCue编辑器,这个编辑器可以用于创建GameplayCue,但你也可以手动创建,只需要使用蓝图继承GameplayCueNotify_xxx类,之后再绑定GamplayCue标签即可。

GameplayCue必须使用GameplayCue开头的tag,例如GameplayCue.ElectricalSparks或者”GameplayCue.WaterSplash.Big。

你可以在蓝图或者c++中重写OnActive、WhileActive()、Removed()、Executed()进行控制。

我能找到的唯一资料就是Tom Looman大神的视频(可以算是官方教程了)
https://youtu.be/Tu5AJKNe1Ok?t=900

使用GameplayCue编辑器来创建

在GameplayCue编辑器中,在新增按钮左边输入栏输入想要创建的标签(必须以GameplayCue.开头),再点击新建即可添加成功。之后就需要为标签添加对应的处理器。

点击处理器列下方对应新增按钮,之后就会新增处理器会弹出Notify创建界面,以下是我对界面中说明文字的翻译:

GameplayCue通知

GameplayCue Notifies are stand alone handlers, similiar to AnimNotifies. Most GameplyCues can be implemented through these notifies. Notifies excel at handling standardized effects. The classes below provide the most common functionality needed.

GameplayCue Notifies是类似AnimNotifies的独立处理器。大多数GameplyCues都可以使用以下两个notifies实现。notifies处理标准化效果(与自定义BP事件相对)。下面的类提供了最常用的功能。

GameplayCueNotifyStatic

A non instantiated UObject that acts as a handler for a GameplayCue. These are useful for one-off “burst” effects.

一个用于处理GameplayCue的非实例化的UObject,适用于一次性的突发effects。

GameplayCueNotifyActor

An instantiated Actor that acts as a handler of a GameplayCue. Since they are instantiated, they can maintain state and tick/update every frame if necessary.

一个用于处理GameplayCue的实例化的Actor。因为是实例化的,所以可以维护状态,并且在在必要的情况下可以在每一帧进行处理。

点击会创建AGameplayCueNotify_Actor

自定义BP事件

GameplayCues can also be implemented via custom events on character blueprints.

To add a custom BP event, open the blueprint and look for custom events starting with GameplayCue.

GameplayCues 也可以通过角色蓝图上的自定义事件来实现。想要增加一个自定义蓝图事件,打开蓝图新增与标签同名的自定义事件。(这个本人没有测试成功,因为自定义事件是不能带有.的)

大致步骤

  1. 可以通过蓝图继承的方式或者GameplayCue编辑器来创建对应的notify
  2. 在创建的notify中设置GameplayCue Tag(这一步成功,Gameplay Cue Editor就能显示绑定)
  3. 重写onActive以及其他状态函数函数。(例如播放粒子效果、声音。如果需要销毁之前播放的Asset,可以在onDestroy中调用reactive函数,并在勾选Notify蓝图中的自动销毁)
  4. 使用GameplayEffect(在GameplayEffect蓝图中的Visible——GameplayCues中添加)或者在ABility类中调用AddGameplayCueToOwner来触发Notify。

有关Notify总结

想要通过GameplayAbility与GameplayEffect触发,需使用GameplayCueNotifyStatic、GameplayCueNotifyActor。

动画则需要使用AnimNotify与AnimNotifyState。

在actionRPG项目中全程使用AnimNotify来驱动各种效果(GameplayAbility=》PlayMontage()=》AnimNotify)