9. 答疑 - Troubleshooting

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 也会正常出现在 ASCSpawnedAttributes 数组之中。如下:

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 对象(译者注:译者也再次提醒,即同一个基类的对象只能有一个)。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值