Gameplay Ability Items
About
Unreal Engine’s Gameplay Ability System (GAS) offers an impressive amount of modularity to gameplay programming for characters and their interactions with environment actors. Swapping out different abilities that are completely independent from the character class makes diversifying designs much easier, and naturally invokes the idea of items that can be picked up or discarded. Unfortunately, in many ways the GAS framework doesn’t seem to mesh as easily with item usage as it could. This is what my Gameplay Ability Items project is focused on fixing.
Overview
Gameplay Ability Items are actors that utilize GAS to contain their functionality. This includes anything from resources like ammo, to what animation to play on the character using them. Characters don’t need to know anything about an item, it just has to try and use the item, pass some optional data, and let the item do the rest. The goal is to have easy to design items that function entirely independently from any character class, while also being easy to integrate with any character that needs to use them.
Ability Items
Ability Items store all of their functionality on gameplay abilities. All the item needs is the ability system component, its ability, and a mesh of some kind. This means while abilities will likely be intended for certain items, they should really be able to work on any item.
Item Abilities
Item Abilities are how Ability Items function. Any targeting, effects, animations, etc. are handled in these classes. Below is an example of a pistol. This ability has no animations right now for the sake of simplicity. It just performs a trace, takes the target data from that trace, and applies damage to the target while spawning some particle effects for feedback.
With just GAS, this normally wouldn’t work. The default targeting system requires a player controller so that it can use player’s control rotation. Wait Trace Target Data From Actor is a custom task developed for ability items that instead uses the actor eyes view transform to fire a trace. This allows item abilities to be used by anything from players to AI to the items themselves.
Trace target actor normally used for GAS. Needs a player controller to function, so it makes it more difficult to use GAS functions intended to be used on target data structures.
Trace function used in the custom gameplay task that can function with any actor type.
The “eyes viewpoint” of an actor is by default just the actor’s origin and rotation. The function to get the viewpoint is also not normally overridable in blueprint. To fix this, ability items have a “GetItemViewpoint” function that overrides “GetActorEyesViewpoint”.
A gun without an explicit owner aiming it, like a gun trap, may want to aim from the barrel of the gun, so that would be the gun’s viewpoint
The boiler plate for an item ability item replaces some of the normal ability events with new events to override. The most important at the base level is UseSuccess, which replaces the ActivateAbility event. This event is called only after the item’s cooldown and cost is checked. The UseFailure events are overridden for feedback on the unsuccessful use of an ability item.
Using an Item Ability
If another actor wants to use an item, they need to send the item a gameplay event with the ability’s assigned use tag.
The use tag corresponds to the method by which the item is meant to be used. Since a machine gun, a pistol, or a bow and arrow would all be used different ways, different tags are used to differentiate input. By sending these tags via enhanced input actions, characters can use a variety of different items with very little logic.
To set up how these use types work, gameplay abilities have 3 different base classes to provide boilerplate for triggered abilities (machine gun), started (pistol), and start/release (bow and arrow). The only real difference between triggered and started is the use tag, and to implement all the developer needs to do is override UseSuccess and add any cost/cooldown effects required. Those two are more or less example implementations. Start-Release, however, introduces new events for different stages of use which should be overridden instead of UseSuccess and is more useful to derive from.