Learning Gameplay Ability System: Components of an Ability

Creating my first Gameplay Ability

Learning new things in Unreal Engine takes time. It can take a while to truly grasp concepts when learning, so I often find it easier to break tasks down into small, mini projects or features. It's how I teach students to approach complex problems in my 'Emergent Games Technology' module I teach at Staffordshire University.

I want to learn the Gameplay Ability System within Unreal Engine - to help with this, I'm slowly creating small components that help me understand how the system works, and contribute to a larger gameplay prototype project.

The first objective was to understand how to create abilities, and the components needed. As such, this post outlines how the first ability was constructed (not a tutorial, but a documentation)

Anatomy of an Ability

For the early stage abilities, we will need:

  • The ability itself (fireball, melee attack for example)
  • The global cooldown (what restricts abilities from chaining rapidly)
  • The ability cooldown (how long until it can be triggered again)
  • The damage profile/effect (what will happen to the target)

In some cases, depending on the ability, we may need projectiles for the ability or particle systems.

 

Understanding these simple abilities would help me understand how the Gameplay Ability System can be leveraged for building interesting gameplay abilities.

 

Let's start with the simple melee attack.

Melee Attack

The melee attack ability is quite straight forward:

  • We commit the ability which makes sure we apply all related gameplay components (resource usage etc which currently isn't implemented).
  • We then initiate the global cooldown which prevents other abilities from being triggered for x amount of time.
  • The ability is fired, in this case it's a simple sphere trace to detect what can be hit - this logic can be coded differently depending on how many targets we want to hit.
  • We get the Gameplay Ability System and apply the damage effect to the target (effectively doing an 'apply damage' using GAS).
  • Currently we use a Wait Gameplay Event if there's not a target, however I'm not sure if this is needed.
  • We commit the ability cooldown ensuring the cooldown for the ability is initiated, this means this ability can't fire until this is completed.
  • Ability is ended.

 

The ability handles what happens when it is triggered by tags. The ability has a few gameplay tags that both block and label the active ability.

While this ability controls the ability execution itself, it is reliant on a number of gameplay effect source files as well as other elements. This includes:

  • The gameplay effect which controls the ability cooldown
  • The gameplay effect that controls the global cooldown
  • The gameplay effect that applies the damage profile to the target.

These look like this:

Attack Ability Cooldown

image

The cooldown Gameplay Effect has a few important elements and settings that help prevent this ability from being able to be called constantly.

 

The duration policy dictates whether there's a timeframe attached to the effect, or it happens instantly. Because we want there to be a timeframe attached to a cooldown, we set it to 'Has Duration' and set it to 2 seconds (Scalable Float Magnitude)

 

We apply a gameplay tag of Tests.Attack.Cooldown which I've created to track what active cooldowns are running/active.

 

We make sure there's no stacking, although we can do stacking abilities.

 

There's many areas of this that aren't completely clear to me but with further playing, I'm sure it will make more sense.

Attack Damage Profile

image

The damage Gameplay Effect is the same type of effect as the cooldown, however it has different settings which help determine how the damage is applied to the target actor.

 

The duration policy is now set to instant, as we want the damage to be applied instantly when this is fired.

 

We have Gameplay Effect Modifiers in this one, as the modifiers help us impact the Gameplay Attributes attached to our target (health, in this instance). We add a negative number to this gameplay attributes to minus this from health. The Gameplay Attributes system is how we address things like resource usage, and would be also leveraged for usage of spells.

 

We have one stack with an expiration policy of clearing entire stack, however this could also likely be non stacking.

Global Cooldown Gameplay Effect

image

The global cooldown Gameplay Effect is triggered every time you perform an ability, as it helps provide a gap between each individual ability allowing easier synchronisation.

 

The duration policy is however long you want the GCD to run for, in this instance, it's 1 second however it can be adjusted.

 

We have Gameplay Effect component tags have been added as this tag can be used as a 'blocker' tag for abilities. If the tag is present, the ability cannot be triggered, thus forcing a global cooldown.

 

Other than that, the global cooldown is one of the simplest abilities and can be either implemented through ApplyGameplayEffectToOwner node (as shown in base melee ability) or by using it in the ability cooldown function in the class settings.

Final Comments and Notes

While there are a lot of components to this Gameplay Ability System, each individual component is relatively straight forward. One area which may need more exploration is how we can use this in a smart way with inheritence in mind - for example, what is the difference between a heavy attack and a light attack? Do we need to create each of these Gameplay Effects to control cooldowns and damage profiles for each ability, or can we expose certain parameters and utilise the same blueprint code? How can we link these abilities to animation montages? There's a lot of things to answer.

 

The objective of this post is not to be instructional, but to help me record my own understanding of how these systems work for a larger scale project.

Leave a Comment