When I Learning lyra starter game , I find code below. And here comes the question: What is the difference between SetHealth and ApplyModToAttribute?
void ULyraHealthSet::PostAttributeChange(const FGameplayAttribute& Attribute, float OldValue, float NewValue)
{
Super::PostAttributeChange(Attribute, OldValue, NewValue);
if (Attribute == GetMaxHealthAttribute())
{
// Make sure current health is not greater than the new max health.
if (GetHealth() > NewValue)
{
// SetHealth(NewValue); why not use SetHealth directly?
ULyraAbilitySystemComponent\* LyraASC = GetLyraAbilitySystemComponent();
check(LyraASC);
LyraASC->ApplyModToAttribute(GetHealthAttribute(), EGameplayModOp::Override, NewValue);
}
}
if (bOutOfHealth && (GetHealth() > 0.0f))
{
bOutOfHealth = false;
}
}