UAttributeSet::PreAttributeChange
#include "AttributeSet.h"
Access: public
Specifiers: virtual
Description
Called just before any modification changes an attribute's current value, regardless of the source. Override to enforce invariants like clamping Health between 0 and MaxHealth.
Caveats & Gotchas
- • Fires for every kind of change: instant executes, duration-based effect ticks, and direct SetX calls, so it's the right place for clamping logic, not gameplay reactions.
- • NewValue is a mutable reference and assigning to it changes what actually gets applied, but this function must not trigger further gameplay events or callbacks.
Signature
virtual void PreAttributeChange(const FGameplayAttribute& Attribute, float& NewValue) { } Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| Attribute | const FGameplayAttribute& | The attribute about to change. | — |
| NewValue | float& | The value the attribute is about to be set to; modify in place to clamp or override it. | — |
Return Type
void Example
Clamp Health to MaxHealth C++
void UMyHealthSet::PreAttributeChange(const FGameplayAttribute& Attribute, float& NewValue)
{
if (Attribute == GetHealthAttribute())
{
NewValue = FMath::Clamp(NewValue, 0.f, GetMaxHealth());
}
} Tags
Version History
Introduced in: unknown
| Version | Status | Notes |
|---|---|---|
| 5.6 | stable | — |
Feedback
Was this helpful?