reznok / GMCAbilitySystem

An Unreal Engine plugin that adds an ability system to the General Movement Component plugin
MIT License
35 stars 16 forks source link

Make ability cooldown optional like GAS does #25

Closed LeoFabre closed 8 months ago

LeoFabre commented 8 months ago

image

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

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 :

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 :)