9.1 LogAbilitySystem: Warning: Can't activate LocalOnly or LocalPredicted ability %s when not local!
前面的章节提到过,你需要在客户端对ASC
组件进行初始化.
9.2 ScriptStructCache
errors
你需要调用UAbilitySystemGlobals::InitGlobalData()
.
9.3 动画蒙太奇没有复制到客户端 - Animation Montages are not replicating to clients
可以去确认一下在GameplayAbilities中尝试去播放蒙太奇时你是使用的 PlayMontageAndWait
的蓝图节点,而不是直接用 PlayMontage
节点。这个 AbilityTask 会帮助你通过 ASC
去复制蒙太奇,而这是原本初始的 PlayMontage
无法实现的。
9.4 复制的Actor蓝图将AttributeSets指针指向空 - Duplicating Blueprint Actors is setting AttributeSets to nullptr
当你利用已有的Actor蓝图去复制的时候,复制的蓝图上的AttributeSet
指针会指向nullptr,这是 Unreal Engine已知的一个bug。针对这个问题现在以及有了一些应对方法。我已经成功测试过一种方法,不去在我的类中创建专门的 AttributeSet
指针(即不在.h文件中创建指针,也不在构造函数中调用 CreateDefaultSubobject
),取而代之的,我是直接在 PostInitializeComponents()
函数中将 AttributeSets
添加给 ASC
(这一点并没有在示例项目中实现)。复制出来的 AttributeSets
也会正常出现在 ASC
的 SpawnedAttributes
数组之中。如下:
void AGDPlayerState::PostInitializeComponents()
{
Super::PostInitializeComponents();
if (AbilitySystemComponent)
{
AbilitySystemComponent->AddSet<UGDAttributeSetBase>();
// ... any other AttributeSets that you may have
}
}
这种情况下,你就不能调用原先那种 由宏为 AttributeSet
生成的方便的函数方法了,比如说那些很方便的访问器和构造器,当然ASC
也提供了一些原生的函数方法可以使用:
/** Returns current (final) value of an attribute */
float GetNumericAttribute(const FGameplayAttribute &Attribute) const;
/** Sets the base value of an attribute. Existing active modifiers are NOT cleared and will act upon the new base value. */
void SetNumericAttributeBase(const FGameplayAttribute &Attribute, float NewBaseValue);
比如哦,现在要实现 GetHealth()
方法的话,如下:
float AGDPlayerState::GetHealth() const
{
if (AbilitySystemComponent)
{
return AbilitySystemComponent->GetNumericAttribute(UGDAttributeSetBase::GetHealthAttribute());
}
return 0.0f;
}
设置(初始化)生命值的 Attribute
方法如下:
const float NewHealth = 100.0f;
if (AbilitySystemComponent)
{
AbilitySystemComponent->SetNumericAttributeBase(UGDAttributeSetBase::GetHealthAttribute(), NewHealth);
}
这里再提醒一个前面小节提到过的问题,ASC
只允许每个 AttributeSet
类型有一个 AttributeSet
对象(译者注:译者也再次提醒,即同一个基类的对象只能有一个)。