Hi, regarding Gameplay effect, let assume we have two stats:
`UPROPERTY(BlueprintReadOnly)
FGameplayAttributeData Shield;
ATTRIBUTE_ACCESSORS(UAttributeSet, Shield);
UPROPERTY(BlueprintReadOnly)
FGameplayAttributeData MaxShield;
ATTRIBUTE_ACCESSORS(UAttributeSet, MaxShield);`What would be the preferred way to give a temporary buff to Shield and max shield and remove said buff in case the granted value has been depleted?
I have thought about making a GE with duration that act as 2 instant GE with a watcher.
Is there any way to achieve that?
If we take as example values that MaxShield is 100 by default and you’d like to give temporary +30 MaxShield that gets removed when current Shield goes below 100 again.
- You can apply an Infinite GE: GE_Overshield that grants +30 MaxShield (server-side, client prediction optional).
- Give it some asset tag (Components: Tags This Effect Has) like: Shielding.ShieldEffect
- If you can have multiple GEs that apply overshield, give them all this tag.
- Since this is an Infinite GE, the MaxShield.Base will be 100, and MaxShield.Current will be 130.
- You then apply an Instant GE: GE_Overshield that permanently modifies +30 Shield (server-side).
- You can then grant an ability and activate it right away, that listens for Shield changes via a “Wait for Attribute Change with Comparison”. I refer to these types of abilities that immediately activate and wait for events as reactive abilities.
- If the current shield value goes below MaxShield.Base, call RemoveActiveEffectsWithTag( Shielding.ShieldEffect ).
With this implementation you can temporarily increase MaxShield, increase current shield by the same amount and remove the MaxShield once the shield goes below the base value again. If you want to have more adaptive thresholds, like if you have multiple Overshield effects active and you want to remove them at different thresholds, you can use a general WaitForAttributeChange task instead that fires on any Shield change, and then compare to your dynamic threshold.
I’ll show some screenshots as example. Ignore the MaxHealth naming, I just experimented in a project I had already.
So here is what the place looks like where you apply the shield. It does take 3 nodes server-side:
[Image Removed]
Here’s the effect that increases MaxShield. The Instant GE that increases Shield I’m sure doesn’t need showing.
[Image Removed]
Here’s the granted GameplayAbility that waits for Shield to drop below MaxShield.Base and then removes all Shielding effects.
[Image Removed]
I would say this combined is a preferred way. If you have many types of shielding temp buffs, I would probably wrap those 3 nodes (infinite effect, instant effect, reactive ability) in a blueprint function library. You can replace the hardcoded +30 MaxShield, +30 Shield with a SetByCaller value or in different GE classes.
Hope this helps!