Ability相关
AttributeSet
AttributeSet显示创建,隐式添加
ALyraCharacterWithAbilities::ALyraCharacterWithAbilities(const FObjectInitializer& ObjectInitializer)
: Super(ObjectInitializer)
{
AbilitySystemComponent = ObjectInitializer.CreateDefaultSubobject<ULyraAbilitySystemComponent>(this, TEXT("AbilitySystemComponent"));
AbilitySystemComponent->SetIsReplicated(true);
AbilitySystemComponent->SetReplicationMode(EGameplayEffectReplicationMode::Mixed);
CreateDefaultSubobject<ULyraHealthSet>(TEXT("HealthSet"));
CreateDefaultSubobject<ULyraCombatSet>(TEXT("CombatSet"));
// AbilitySystemComponent needs to be updated at a high frequency.
NetUpdateFrequency = 100.0f;
}
HealthSet和CombatSet创建后作为ALyraCharacterWithAbilities的Subobj存在
void UAbilitySystemComponent::InitializeComponent()
{
Super::InitializeComponent();
// Look for DSO AttributeSets (note we are currently requiring all attribute sets to be subobjects of the same owner. This doesn't *have* to be the case forever.
AActor *Owner = GetOwner();
InitAbilityActorInfo(Owner, Owner); // Default init to our outer owner
// cleanup any bad data that may have gotten into SpawnedAttributes
for (int32 Idx = SpawnedAttributes.Num()-1; Idx >= 0; --Idx)
{
if (SpawnedAttributes[Idx] == nullptr)
{
SpawnedAttributes.RemoveAt(Idx);
}
}
TArray<UObject*> ChildObjects;
GetObjectsWithOuter(Owner, ChildObjects, false, RF_NoFlags, EInternalObjectFlags::Garbage);
for (UObject* Obj : ChildObjects)
{
UAttributeSet* Set = Cast<UAttributeSet>(Obj);
if (Set)
{
SpawnedAttributes.AddUnique(Set);
bIsNetDirty = true;
}
}
SetSpawnedAttributesListDirty();
}
此处Component的outer为Actor,从Actor的Subobj拿到AttributeSets并添加到AbilityComponent
标签:工程,Idx,TEXT,Lyra,AbilitySystemComponent,Owner,CreateDefaultSubobject,SpawnedAttr From: https://www.cnblogs.com/rpg3d/p/16795079.html