你好!开发背景为:项目使用了Mass框架来制作NPC,故NPC的Actor是会重复使用的。项目的主要AI逻辑由状态树控制。
需求:NPC从高精度切换到低精度的时候,需要保存StateTree当前处于到哪个状态。当从低精度切回高精度的时候,会直接进入到那个状态,且保留运行时数据。例如:从高精度切低精度时,StateTree处于Root->C状态,那么当低精度切回高精度时,StateTree会在一开始就直接进入Root->C状态。
UE5.5.4上的原有实现:直接保存FStateTreeInstanceData,当构造FStateTreeExecutionContext时,将保存的FStateTreeInstanceData的放进去,就能实现这样的效果。
UE5.7.2上遇到的问题:5.7.2在FStateTreeInstanceStorage中新增了RuntimeValidationData变量,该变量外部无法直接访问与修改,他会记录Owner。由于项目的NPC是复用的,因此Storage.GetRuntimeValidation().SetContext(&Owner, &RootStateTree, bWriteAccessAcquired); 这一行代码会触发Ensure,由于Owner不为空且Owner与NewOwner不同。具体Ensure行数StateTree\Source\StateTreeModule\Private\Debugger\StateTreeRuntimeValidation.cpp 的第88行。
【
if (Owner.IsValid() && Owner != NewOwner)
{
ensureAlwaysMsgf(false, TEXT(“StateTree runtime check failed: The owner ‘%s’ is different from the previously set ‘%s’.\n”
“Make sure you initialize FStateTreeExecutionContext with the same values every time.\n”
“Auto deactivate Runtime check StateTree.RuntimeValidation.Context to prevent reporting the same error multiple times.”)
, InNewOwner ? *InNewOwner->GetFullName() : TEXT(“owner”), *Owner.Get()->GetFullName());
Private::bRuntimeValidationContext = false;
}
】
想问:有没有什么办法能够实现复写状态树数据,忽略条件的判断,直接跳转到目标状态。或者有什么办法,能够绕过Ensure的报错。
[Attachment Removed]