I made a character whose maximum HP is 100. Now I want to use gas to make a buff. The effect is like this: it can make the character recover 50 HP in 2 seconds, and the amount of HP after recovery can’t be more than 100. After that, it will return to its original appearance.
So I made a GameEffect, using the has duration type, with scalable float magnet set to 2, and add character’s HP attribute 50. Then there is a problem, because GameEffect of has duration type will not call the function UAttributeset:: PostGameplayEffectexEcution after execution (I usually limit the value range of HP here), so I can’t limit the range of returned HP, and the amount of HP after recovery will over 100.
Locally, in my project, I use PostGameplayEffectExecute() to clamp the Health attribute:
else if (Data.EvaluatedData.Attribute == GetHealthAttribute())
{
SetHealth(FMath::Clamp(GetHealth(), 0.0f, GetMaxHealth()));
}
I understand that you say that this doesn’t make a difference, but perhaps you also need to add clamping to the PreAttributeChange() function as well inside your attributes. For my project, I have this:
In-game, my Health does not exceed my current Max Health. As an additional test, to at least ensure this gameplay effect was doing something, I set the modifier magnitude to -1 instead of 50; subtracting one from my Health every second. Making this change showed my character losing health per second, so its safe to say that when using a value of 50, or anything positive, meant it was attempting to add to my Health. But due to my two different clamps, it would not go past my Max Health.