this is my code
HopperAttributeSet.cpp:
// Fill out your copyright notice in the Description page of Project Settings.
include “Core/Abilities/HopperAttributeSet.h”
include “Net/UnrealNetwork.h”
UHopperAttributeSet::UHopperAttributeSet()
{
}
void UHopperAttributeSet::GetLifetimeReplicatedProps(TArray& OutLifetimeProps) const
{
Super::GetLifetimeReplicatedProps(OutLifetimeProps);
//这个宏用来指定哪些属性需要在多人游戏中复制,用于注册属性以进行复制。
DOREPLIFETIME(UHopperAttributeSet, Health);
}
void UHopperAttributeSet::OnRep_Health(const FGameplayAttributeData& OldValue)
{
//这个特定的宏用于指定当某个属性被复制时应该调用一个通知函数
GAMEPLAYATTRIBUTE_REPNOTIFY(UHopperAttributeSet, Health, OldValue);
}
HopperAttributeSet.h:
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
include “CoreMinimal.h”
include “AttributeSet.h”
include “HopperAttributeSet.generated.h”
#define ATTRIBUTE_ACCESSORS(ClassName, PropertyName)
GAMEPLAYATTRIBUTE_PROPERTY_GETTER(ClassName, PropertyName)
GAMEPLAYATTRIBUTE_VALUE_GETTER(PropertyName)
GAMEPLAYATTRIBUTE_VALUE_SETTER(PropertyName)
GAMEPLAYATTRIBUTE_VALUE_INITTER(PropertyName)
/**
*
*/
UCLASS()
class ABILITYDEMO2_API UHopperAttributeSet : public UAttributeSet
{
GENERATED_BODY()
public:
UHopperAttributeSet();
virtual void GetLifetimeReplicatedProps(TArray<FLifetimeProperty>& OutLifetimeProps) const override;
UPROPERTY(BlueprintReadOnly,ReplicatedUsing = OnRep_Health,Category = "Attributes")
FGameplayAttributeData Health;
ATTRIBUTE_ACCESSORS(UHopperAttributeSet, Health);
UFUNCTION()
virtual void OnRep_Health(const FGameplayAttributeData& OldValue);
};