Source\GameplayAbilities\Public\AttributeSet.h
GAMEPLAYATTRIBUTE_REPNOTIFY
has three parameters:
#define GAMEPLAYATTRIBUTE_REPNOTIFY(ClassName, PropertyName, OldValue) \
{ \
static FProperty* ThisProperty = FindFieldChecked<FProperty>(ClassName::StaticClass(), GET_MEMBER_NAME_CHECKED(ClassName, PropertyName)); \
GetOwningAbilitySystemComponent()->SetBaseAttributeValueFromReplication(FGameplayAttribute(ThisProperty), PropertyName, OldValue); \
}
AttributeSetBase.h
#pragma once
#include "AttributeSet.h"
#include "CoreMinimal.h"
#include "AttributeSetBase.generated.h"
UCLASS()
class SANDBOX_API UAttributeSetBase : public UAttributeSet
{
GENERATED_BODY()
public:
UPROPERTY(BlueprintReadWrite, EditAnywhere, ReplicatedUsing = OnRep_Stamina, Category = "Attributes | Stamina")
FGameplayAttributeData Stamina;
UFUNCTION()
void OnRep_Stamina(const FGameplayAttributeData& Previous);
static FGameplayAttribute AttributeStamina();
/** A Replicated Boolean Flag */
UPROPERTY(Replicated)
uint32 bFlag:1;
/** A Replicated Array Of Integers */
UPROPERTY(Replicated)
TArray<uint32> IntegerArray;
};
AttributeSetBase.cpp
#include "AttributeSetBase.h"
#include "AbilitySystemComponent.h"
#include "Net/UnrealNetwork.h"
void UAttributeSetBase::OnRep_Stamina(const FGameplayAttributeData& Previous)
{
const auto PreviousValue = Previous.GetCurrentValue();
GAMEPLAYATTRIBUTE_REPNOTIFY(UAttributeSetBase, Stamina, PreviousValue);
}
FGameplayAttribute UAttributeSetBase::AttributeStamina()
{
static FProperty* Property = FindFieldChecked<FProperty>(UAttributeSetBase::StaticClass(),
GET_MEMBER_NAME_CHECKED(UAttributeSetBase, Stamina));
return FGameplayAttribute(Property);
}
void UAttributeSetBase::GetLifetimeReplicatedProps(TArray<FLifetimeProperty>& OutLifetimeProps) const
{
Super::GetLifetimeReplicatedProps(OutLifetimeProps);
DOREPLIFETIME(UAttributeSetBase, bFlag);
DOREPLIFETIME(UAttributeSetBase, IntegerArray);
}
Use FProperty, UProperty is deprecated since 4.25.
If you encounter with GetLifetimeReplicatedProps
error:
https://www.ue4community.wiki/Legacy/Replication
Useful thread: GameplayAbilities and you. - Community Content, Tools and Tutorials - Unreal Engine Forums
Getting old value question: c++ - How to get the delta value of an GameplayAbility attribute on client (after attribute value change)? - Stack Overflow