UAttributeSet
#include "AttributeSet.h" Description
The base class for defining numeric attributes (health, stamina, damage) that GAS effects can read and modify. Subclass this and declare FGameplayAttributeData properties.
Caveats & Gotchas
- • Use the ATTRIBUTE_ACCESSORS macro to generate GetHealth/SetHealth/InitHealth helpers — writing these by hand is error-prone.
- • PreAttributeChange and PostAttributeChange are your hooks to clamp values. Clamping in PreAttributeChange is preferred to avoid out-of-range reads, but the value is already applied by the time PostAttributeChange fires.
- • Attributes are replicated individually — mark them with UPROPERTY(Replicated) and implement GetLifetimeReplicatedProps. Forgetting replication means clients see stale values.
Example
Minimal attribute set with health C++
UCLASS()
class UMyAttributeSet : public UAttributeSet
{
GENERATED_BODY()
public:
UPROPERTY(BlueprintReadOnly, ReplicatedUsing=OnRep_Health, Category="Attributes")
FGameplayAttributeData Health;
ATTRIBUTE_ACCESSORS(UMyAttributeSet, Health)
virtual void PreAttributeChange(const FGameplayAttribute& Attribute, float& NewValue) override
{
if (Attribute == GetHealthAttribute())
NewValue = FMath::Clamp(NewValue, 0.f, GetMaxHealth());
}
}; Functions (21)
Networking 6 ▼
| Access | Type | Name |
|---|---|---|
| public | function | UAttributeSet::IsNameStableForNetworking |
| public | function | UAttributeSet::IsSupportedForNetworking |
| public | function | UAttributeSet::PostNetReceive |
| public | function | UAttributeSet::PreNetReceive |
| public | function | UAttributeSet::RegisterReplicationFragments |
| public | function | UAttributeSet::SetNetAddressable |
Utility 2 ▼
| Access | Type | Name |
|---|---|---|
| public | function | UAttributeSet::GetAttributesFromSetClass |
| public | function | UAttributeSet::PrintDebug |
Effects 7 ▼
| Access | Type | Name |
|---|---|---|
| public | function | UAttributeSet::PostAttributeChange |
| public | function | UAttributeSet::PostGameplayEffectExecute |
| public | function | UAttributeSet::PreAttributeChange |
| public | function | UAttributeSet::PreGameplayEffectExecute |
| public | function | UAttributeSet::OnAttributeAggregatorCreated |
| public | function | UAttributeSet::PostAttributeBaseChange |
| public | function | UAttributeSet::PreAttributeBaseChange |
Initialization 2 ▼
| Access | Type | Name |
|---|---|---|
| public | function | UAttributeSet::InitFromMetaDataTable |
| public | function | UAttributeSet::ShouldInitProperty |
Ownership 4 ▼
| Access | Type | Name |
|---|---|---|
| public | function | UAttributeSet::GetOwningAbilitySystemComponent |
| public | function | UAttributeSet::GetOwningAbilitySystemComponentChecked |
| public | function | UAttributeSet::GetOwningActor |
| public | function | UAttributeSet::GetActorInfo |
Tags
Version History
Introduced in: unknown
| Version | Status | Notes |
|---|---|---|
| 5.6 | stable | — |
Feedback
Was this helpful?