本文使用 UE4.26,以及 GAS 系统,记录一下 Montage Next Section 的一个问题
一、问题背景和表现
1.1 问题背景
在 UE4 中,有时候需要在播放 Montage 的同时修改 Section 的连接关系(关于 Montage 和 Section 的含义和用法可以参考 这里),比如有时候想第 1 段后边接第 2 段,有时候想接第 3 段,这时候可以用 UGameplayAbility::MontageSetNextSectionName
设置第一段的下一段是哪个,然后就可以达到第一段结束之后,直接从哪一段继续播的效果。
如果不想当前段播完,而是直接跳转到下一段,从接口上看,没有一个接口是 “JumpToNextSection” 这种功能,只有 “MontageJumpToSection” 这样的接口,所以需要一个 “GetNextSection” 这样的接口拿到当前 Section 的下一个 Section 是哪个。
1.2 问题表现
问题表现一句话总结就是:FAnimMontageInstance::GetNextSection()
和 FAnimMontageInstance::GetNextSectionID
结果不一致。
FName FAnimMontageInstance::GetNextSection() const
{
if (Montage)
{
float CurrentPosition;
const int32 CurrentSectionIndex = Montage->GetAnimCompositeSectionIndexFromPos(Position, CurrentPosition);
if (Montage->IsValidSectionIndex(CurrentSectionIndex))
{
FCompositeSection& CurrentSection = Montage->GetAnimCompositeSection(CurrentSectionIndex);
return CurrentSection.NextSectionName;
}
}
return NAME_None;
}
int32 FAnimMontageInstance::GetNextSectionID(int32 const