需要在 UObject
中重载 GetWorld
virtual UWorld* GetWorld() const override;
并在cpp文件中编写以下实现
UWorld* UNPCBehaviorBase::GetWorld() const
{
if (ULevel* Level = GetTypedOuter<ULevel>())
{
return Level->OwningWorld;
}
return nullptr;
}
编译即可
参考文献:
[[1] 知乎:Bunny.Lann][https://www.zhihu.com/pin/1195113257248116736]