How-To: Add Ability Costs
Goal: charge something other than an attribute - a tag-stack resource, a consumable, a custom rule - and have the UI grey the button out before the player presses it.
1. Add a cost object
UCrimsonGameplayAbility holds an array of UCrimsonAbilityCost instances. Every one must pass for the ability to activate, and all of them are applied together on commit.
In the ability's Class Defaults, add an entry to Additional Costs and choose a cost class - CrimsonAbilityCost_PlayerTagStack ships with the plugin.
2. Write a custom cost
Subclass UCrimsonAbilityCost and override two BlueprintNativeEvents.
Right-click -> Blueprint Class -> `CrimsonAbilityCost`, then override K2 Check Cost (return whether the player can pay) and K2 Apply Cost (deduct it).
3. Grey out the UI before the press
Check Ability Cost For UI runs the same checks without activating, so a button can reflect affordability every frame.
Bind the button's Is Enabled to Check Ability Cost For UI on the ability.
See also
- Concept: Gameplay Ability