RSExampleAttributeSet.h
Click a line number to link it. Shift-click to select a range.
| 1 | // Copyright (c) 2026 Reignance Studios. MIT License, see LICENSE. |
| 2 | // Example only: copy into your game module and rename the RSExample prefix. |
| 3 | |
| 4 | #pragma once |
| 5 | |
| 6 | #include "CoreMinimal.h" |
| 7 | #include "AttributeSet.h" |
| 8 | #include "AbilitySystemComponent.h" |
| 9 | #include "RSExampleAttributeSet.generated.h" |
| 10 | |
| 11 | #define RS_ATTRIBUTE_ACCESSORS(ClassName, PropertyName) \ |
| 12 | GAMEPLAYATTRIBUTE_PROPERTY_GETTER(ClassName, PropertyName) \ |
| 13 | GAMEPLAYATTRIBUTE_VALUE_GETTER(PropertyName) \ |
| 14 | GAMEPLAYATTRIBUTE_VALUE_SETTER(PropertyName) \ |
| 15 | GAMEPLAYATTRIBUTE_VALUE_INITTER(PropertyName) |
| 16 | |
| 17 | UCLASS() |
| 18 | class URSExampleAttributeSet : public UAttributeSet |
| 19 | { |
| 20 | GENERATED_BODY() |
| 21 | |
| 22 | public: |
| 23 | UPROPERTY(BlueprintReadOnly, ReplicatedUsing = OnRep_Health, Category = "Attributes") |
| 24 | FGameplayAttributeData Health; |
| 25 | RS_ATTRIBUTE_ACCESSORS(URSExampleAttributeSet, Health) |
| 26 | |
| 27 | UPROPERTY(BlueprintReadOnly, ReplicatedUsing = OnRep_Stamina, Category = "Attributes") |
| 28 | FGameplayAttributeData Stamina; |
| 29 | RS_ATTRIBUTE_ACCESSORS(URSExampleAttributeSet, Stamina) |
| 30 | |
| 31 | virtual void GetLifetimeReplicatedProps(TArray<FLifetimeProperty>& OutLifetimeProps) const override; |
| 32 | |
| 33 | protected: |
| 34 | // GAMEPLAYATTRIBUTE_REPNOTIFY keeps client prediction intact: it tells the |
| 35 | // ASC about the new server value so predicted changes are re-applied on top. |
| 36 | UFUNCTION() |
| 37 | void OnRep_Health(const FGameplayAttributeData& OldValue); |
| 38 | |
| 39 | UFUNCTION() |
| 40 | void OnRep_Stamina(const FGameplayAttributeData& OldValue); |
| 41 | }; |