Error13. GAS|属性顺序导致的GE错乱
大约 2 分钟
省流
先设置Max的属性,再设置正常的属性。
问题描述
问题排除
检查AttributeSet
#define ATTRIBUTE_ACCESSORS(ClassName, PropertyName) \
GAMEPLAYATTRIBUTE_PROPERTY_GETTER(ClassName, PropertyName) \
GAMEPLAYATTRIBUTE_VALUE_GETTER(PropertyName) \
GAMEPLAYATTRIBUTE_VALUE_SETTER(PropertyName) \
GAMEPLAYATTRIBUTE_VALUE_INITTER(PropertyName)
class EXORCIST_API UExorcistAttributeSet : public UAttributeSet
{
GENERATED_BODY()
public:
UExorcistAttributeSet();
//重写复制函数
virtual void GetLifetimeReplicatedProps(TArray<FLifetimeProperty>& OutLifetimeProps) const override;
//属性修改前调用的函数,用于钳制输出或者一些规则设定,但他不会真正的修改某个Attributes属性
virtual void PreAttributeChange(const FGameplayAttribute& Attribute, float& NewValue) override;
//设置Health
UPROPERTY(BlueprintReadOnly, Category = "Health", ReplicatedUsing = OnRep_Health)
FGameplayAttributeData Health;
ATTRIBUTE_ACCESSORS(UExorcistAttributeSet, Health);
//设置最大Health
UPROPERTY(BlueprintReadOnly, Category = "Health", ReplicatedUsing = OnRep_MaxHealth)
FGameplayAttributeData MaxHealth;
ATTRIBUTE_ACCESSORS(UExorcistAttributeSet, MaxHealth);
}
UExorcistAttributeSet::UExorcistAttributeSet()
{
InitHealth(100.f);
InitMaxHealth(100.f);
}
void UExorcistAttributeSet::GetLifetimeReplicatedProps(TArray<FLifetimeProperty>& OutLifetimeProps) const
{
Super::GetLifetimeReplicatedProps(OutLifetimeProps);
DOREPLIFETIME_CONDITION_NOTIFY(UExorcistAttributeSet, Health, COND_None, REPNOTIFY_Always);
DOREPLIFETIME_CONDITION_NOTIFY(UExorcistAttributeSet, MaxHealth, COND_None, REPNOTIFY_Always);
}
void UExorcistAttributeSet::OnRep_Health(const FGameplayAttributeData& OldHealth)
{
GAMEPLAYATTRIBUTE_REPNOTIFY(UExorcistAttributeSet, Health, OldHealth);
}
void UExorcistAttributeSet::OnRep_MaxHealth(const FGameplayAttributeData& OldHealth)
{
GAMEPLAYATTRIBUTE_REPNOTIFY(UExorcistAttributeSet, MaxHealth, OldHealth);
}
检查GameplayEffect
void AExorcistCharacterHero::PossessedBy(AController * NewController)
{
Super::PossessedBy(NewController);
InitGE();
}
void AExorcistCharacterHero::OnRep_PlayerState()
{
Super::OnRep_PlayerState();
}