reznok/GMCAbilitySystem

Make ability cooldown optional like GAS does

Closed this issue · 0 comments

image

I'm implementing a Dashing GA that needs two conditions to be satisfied :

  • Having landed after the last dash (I use an attribute for that, I might use a Gameplaytag instead but it works for now)
  • Not being in a 3 seconds CooldownTime on that GA

With the current implementation, BeginAbility forces the Cooldown time to be set.

This is currently holding me back to use the elsewise useful CooldownTime of the ability :
If I do a dash and take much altitude, and try to dash again while airborne after 3 seconds of airtime (which does not satisfy the LandedAfterDash condition), the ability begins, then CanAffordAbilityCost is false, then my ability ends without executing the dash logic - BUT, the cooldown gets set anyway.
I want my dash ability to get cooled down only if it actually dashed.

GAS addresses this problem with the following implem :

  • The Cooldown is only set when CommitCooldown() is called in the GA.
  • The Ability Cost is only applied when CommitCost() is called in the GA.
  • There is a method called CommitAbility() method that calls both CommitCooldown() and CommitCost().

More on this here :

After a GameplayAbility calls Activate(), it can optionally commit the cost and cooldown at any time using UGameplayAbility::CommitAbility() which calls UGameplayAbility::CommitCost() and UGameplayAbility::CommitCooldown(). The designer may choose to call CommitCost() or CommitCooldown() separately if they shouldn't be committed at the same time. Committing cost and cooldown calls CheckCost() and CheckCooldown() one more time and is the last chance for the GameplayAbility to fail related to them. The owning ASC's Attributes could potentially change after a GameplayAbility is activated, failing to meet the cost at time of commit. Committing the cost and cooldown can be locally predicted if the prediction key is valid at the time of commit.

If I had this responsibility separation and no cooldown at activation, I could call CommitAbility() instead of CommitAbilityCost(), which would both set the cooldown and apply the cost GE at the same time, and solve the "cooldown being forced at activation" issue I'm facing.

I'll contribute this very shortly, if you think there is a better solution or an enhancement to this one, LMK !

Cheers :)