01新手村
1.ReplicationMode的具体含义
这玩意仍理不清,GE不复制给客户端AI意味着他们在客户端属性不变?那我要更新血条敌人怎么办
2.InitActorInfo的时机:
PS:我怎么记得AcknowledgePossession中的PlayerState就是有效的。
对玩家来说:
初始化前提:Controller,PlayerState,Character都有效。
服务器:Pawn的PossessedBy
客户端:OnRep_PlayerState中。
对NPC来说:
BeginPlay
void AAuraPlayer::PossessedBy(AController* NewController)
{
Super::PossessedBy(NewController);
SetupActorInfo();
}
void AAuraPlayer::OnRep_PlayerState()
{
Super::OnRep_PlayerState();
SetupActorInfo();
}
void AAuraPlayer::SetupActorInfo()
{
if (AAuraPlayerState* AuraPS = GetPlayerState<AAuraPlayerState>())
{
AuraAttributeSet = AuraPS->GetAuraAttributeSet();
AuraASC = Cast<UAuraAbilitySystemComponent>(AuraPS->GetAbilitySystemComponent());
if (AuraASC)
{
AuraASC->InitAbilityActorInfo(GetController(),this);
}
}
}
3.创建一个属性的样板代码
这玩意需要包含AbilitysystemComponent.h
#define ATTRIBUTE_ACCESSORS(ClassName, PropertyName) \
GAMEPLAYATTRIBUTE_PROPERTY_GETTER(ClassName, PropertyName) \
GAMEPLAYATTRIBUTE_VALUE_GETTER(PropertyName) \
GAMEPLAYATTRIBUTE_VALUE_SETTER(PropertyName) \
GAMEPLAYATTRIBUTE_VALUE_INITTER(PropertyName)
UPROPERTY(BlueprintReadOnly,ReplicatedUsing=OnRep_Health,Category="FirstAttribute")
FGameplayAttributeData Health;
UFUNCTION()
void OnRep_Health(const FGameplayAttributeData& OldAttribute);
ATTRIBUTE_ACCESSORS(ThisClass,Health);
DOREPLIFETIME_CONDITION_NOTIFY(UAuraAttributeSet,Health,COND_None,REPNOTIFY_Always);
GAMEPLAYATTRIBUTE_REPNOTIFY(ThisClass,Health,OldAttribute);