Unreal Engine·Gameplay Ability System·Gameplay Abilities

From Wait Delays to Play Montage: 10 useful GAS Ability Tasks

The Ability Tasks I reach for most in Unreal's Gameplay Ability System (GAS): Wait Delay, Wait for Attribute Change, Play Montage and Wait, and more, with what each one is for.

Today you are going to learn some useful Ability Tasks that you can use in your Gameplay Abilities to speed up your development process.

As a refresher, the Gameplay Ability System in Unreal Engine has a kind of object called Ability Task.

Ability Tasks allow you to condense complex behavior into a single node that you can use multiple times to make your work easier.

In the future I will show you how to create them, but today, let’s get right into some useful already existing Ability Tasks.

Wait Delay

This is one of the simplest tasks of all. The same way that the delay node in blueprint waits for a certain time in seconds, this is the Ability Task version of the delay node.

Why would you want to use this instead of a normal delay node you ask?

That is because the delay node will run no matter what, but this, being an ability task, will abort its execution if the ability ends.

So you will not have weird behavior of an ended ability suddenly executing code.

Wait for Attribute Change

Select a GAS Attribute, and this task will fire its On Change delegate once that attribute changes. You can set it to fire only one time and that’s it, or to continue firing every time the attribute changes.

Useful if you have abilities that react to attribute changes, but need to do complex calculations with it.

Wait for Attribute Change Ratio Threshold

Similar to the previous node this reacts to attribute changes, but it allows us to do complex logic that is quite common. Given two attributes, you can compare their ratios using a float, and decide what you are looking for.

This is the task you want to use if you have abilities that do cool stuff when the player is on low health for instance.

You could set the Numerator to Health, Denominator to MaxHealth, Comparison Type to Less Than and Comparison Value to 0.3. Suddenly you have a task that will fire once the player reaches below 30% health, and you can grant a buff to the player, or decide that this is an ability that is only active when player health is above or equal 30%.

As you can see, this is a quite powerful task.

Wait for Ability Activate

This task will fire when an ability with a tag filter provided is Activated.

It is useful if you have abilities that need to do stuff when other Gameplay Ability System abilities activate.

Like, if Dodge ability is activated, a passive ability with this task triggers and spawns a bomb at the player location.

Wait Gameplay Effect Applied to Self

Useful when you want to execute behavior once certain effects are applied to us.

This could be used in a passive ability that has a 10s cooldown that clears any poison that is applied to us. So when a poison effect is applied, if you are not on cooldown, you react and remove the effect.

Wait Gameplay Tag Add to Actor

A simple task that allows us to know when a tag has been applied to an actor. Tags can be a useful way to communicate the Gameplay Ability System with other systems in our project.

So you can have an ability that reacts when the Immune tag is added to us, and spawns a widget on top of the player for instance.

Wait Gameplay Tag Remove from Actor

The same way you can wait for a tag to be added, you can listen for a tag to be removed. Following the previous example you could also listen to the Immune tag being removed and then destroy the widget you created.

But this is also useful for other kind of behavior, you could have an ability that on activation applies a gameplay effect stack of 5 volatile tags, that can be refreshed via gameplay actions, and listen to when those are removed to cause damage to the player, creating an ability that buffs the player, but if they do not keep up gaining stacks will damage the player.

As you can see we can easily create interesting behavior using Unreal Gameplay Ability System using a simple combination of Abilities, Effects and Tags.

Wait Gameplay Tag Query on Actor

If you need complex queries, instead of asking for multiple tags, you can directly create a Query Task that will trigger once a certain Tag Query is true or false.

This allows you to check for complex situations, like having a player attack hit the enemy with a debuff that once the enemy is Poisoned, Burning and Electrified at the same time, the enemy is instantly killed.

Wait Movement Mode Change

Movement is an important part of a character controller, so being able to react to movement mode changes is very useful.

With this you can make your abilities react to the character starting to fall, or the character actually landing on ground again.

You could have a ground slam ability that propels the character up and then wait for the movement mode to change to not be walking on ground again to spawn an area of damage on the ground.

Play Montage and Wait

Finally, last but not least, you have one of the most useful tasks if you are creating melee combat.

This task allows you to play any montage you want on the character that is running the ability, and this will be a Gameplay Ability System montage so it will be replicated over the network by default.

If you want to create any kind of Combo Attack Ability, a Powerful Attack, a Hit Reaction Ability…. this is the task to use.

You can also wait to the montage being interrupted or finished to trigger other behaviors.

As you can see, Ability Tasks are an incredibly powerful Gameplay Ability System tool, and they let you reuse existing behavior to build new, more complex behavior.

Recap

  • The reason to reach for an Ability Task instead of a plain Blueprint node ( Wait Delay over a Delay ) is that the task aborts when the ability ends, so you don’t get an already-finished ability running code later.
  • Wait for Attribute Change Ratio Threshold compares two attributes against each other, which is the clean way to do “below 30% health” logic without wiring up the math yourself.
  • Play Montage and Wait plays through the ASC, so the montage replicates by default, and it gives you interrupted and completed outputs to branch on.

What this doesn’t cover

This is a tour of what these tasks do, not how to build your own ( that is a separate post ) and not the networking detail of when each callback fires on the client versus the server. There are also more Ability Tasks in the engine than the ten here, so once you know the pattern, go read the ones your project needs.

Keep reading

GiveAbilityAndActivateOnce: One-Shot Abilities Without the Cleanup

GiveAbilityAndActivateOnce: One-Shot Abilities Without the Cleanup

Grant an ability, activate it once, and let GAS remove the spec by itself.
Learning about Ability Instancing Policy in GAS

Learning about Ability Instancing Policy in GAS

So many instancing types!
Making Sense of Gameplay Effect Durations

Making Sense of Gameplay Effect Durations

Instant vs Has Duration vs Infinite