使 UObject 蓝图支持 Delay 和 Spawn Actor等功能

2021/02/18 · 笔记 · 技术经验 · 虚幻4 · 1452次阅读

需要在 UObject 中重写 GetWorld

/* MyObject.h */
// ...
virtual UWorld* GetWorld() const override;

并在cpp文件中编写以下实现

/* MyObject.cpp */
UWorld* UMyObject::GetWorld() const
{
   if (ULevel* Level = GetTypedOuter<ULevel>())
   {
      return Level->OwningWorld;
   }
   return nullptr;
}

编译即可


参考文献:
[[1] 知乎:Bunny.Lann][https://www.zhihu.com/pin/1195113257248116736]

标签:UE,虚幻,UObject,蓝图

最后编辑于:2021/11/22 17:41

🎯添加新评论

  1. 123 123
    2021-12-31 17:20

    专业空包代发网,就选www.5adanhw.com

    回复