这篇随笔用于忘记AttributeSet是什么后快速想起来和上手
AttributeSet属性集是表示Actor各种属性值的集合,保存在ASC中,是GE的主要作用目标
比如继承一个AttributeSet后
新建公有成员变量:
UPROPERTY(BlueprintReadOnly , Category = "Health", ReplicatedUsing = OnRep_Health) FGameplayAttributeData Health; ATTRIBUTE_ACCESSOTS(UBasicAttributeSet,Health) 其中ReplicatedUsing = OnRep_Health是强制委托,当这个值被改变时调用OnRep_Health函数ATTRIBUTE_ACCESSOTS属性访问器宏是在属性声明后给属性添加的宏,其定义在源码AttributeSet.h最后:
#define ATTRIBUTE_ACCESSORS(ClassName,PropertyName)\GAMEPLAYATTRUBUTE_PROPERTY_GETTER(ClassName,PropertyName)\
GAMEPLAYATTRUBUTE_VALUE_GETTER(PropertyName)\
GAMEPLAYATTRUBUTE_VALUE_SETTER(PropertyName)\
GAMEPLAYATTRUBUTE_VALUE_INITTER(PropertyName) 代表四个方法: 拿到属性:static FGameplayAttribute UMyHealthSet::GetHealthAttribute();
拿到值:FORCEINLINE float UMyHealthSet::GetHealth()const;
设置值:FORCEINLINE void UMyHealthSet::SetHealth(float NewVal);
初始化值:FORCEINLINE void UMyHealthSet::InitHealth(float Newval); 新建公有成员函数: 更改属性之前调用:virtual void PreAttributeChange(const FGameplayAttribute& Attribute,float& NewValue) override;
更改属性之后调用:virtual void PostGameplayEffectExecute(const FGameplayEffectModCallbackData& Data) override; 配置好GE后给玩家类(比如Character)添加:
protected: UPROPERTY()
class UBasicAttributeSet* BasicAttributeSet;
并且在构造函数里面初始化:
BasicAttributeSet = CreateDefaultSubobject<UBasicAttributeSet>(TEXT("BasicAttributeSet"))
然后在其他类里读取值就是:获得玩家类->GetAbilitySystemComponent->GetFloatAttributeFromAbilitySystemComponent
改变值就是:获得玩家类->GetAbilitySystemComponent->ApplyGameplayEffectToSelf调用一个GE修改该值 标签:UMyHealthSet,AttributeSet,PropertyName,GAS,Unreal,Health,void,属性 From: https://www.cnblogs.com/ikun-proto/p/17365171.html