Where do I do broadcast for GameplayAttribute value change?

Let’s say, my GameplayEffect temporarily adds +500HP for 10 seconds and I want to update the GUI accordingly.

There is PostGameplayEffectExecute() which could be a place to broadcast AttributeChanged events (The approach I see in ARPG sample project). However, I did some test, temporary GameplayEffect like " adds +500HP for 10 seconds" will add to the aggregator stack and do not change the base value, which means it will not trigger PostGameplayEffectExecute().

There is PreAttributeChange() and PreAttributeBaseChange() which would be called when the attribute changes. However, its doc said:

PreAttributeChange/PreAttributeBaseChange: called just before modifications to an Attribute. They are intended to enforce rules on the Attribute’s value, such as “Health must be between 0 and MaxHealth”, and should not trigger in-game reactions to Attribute changes.

So where do I broadcast for Attribute value change?
Also, why is there no PostAttributeChange()/PostAttributeBaseChange?

Thanks,

2 Likes

Ok so I do some digging and found that there is:

DECLARE_MULTICAST_DELEGATE_OneParam(FOnGameplayAttributeValueChange, const FOnAttributeChangeData&);

These delegates are managed by AbilitySystemComponent, (FActiveGameplayEffectsContainer actually). We can get a delegate for specific FGameplayAttribute using:

UAbilitySystemComponent::GetGameplayAttributeValueChangeDelegate(FGameplayAttribute Attribute)

I found that these delegates are used to run the UAbilityTask_WaitAttributeChange(), so I guess that means it is safe to use. Gotta run with it.

================

Also PreAttributeChange() isn’t a good place to do callback, since it is called before the attribute’s value is really changed. Would be nice if there is PostAttributeChange() I guess?