The smallest solution I came up with is
UWorld* UMyClass::GetWorld() const
{
#if WITH_EDITOR
if (IsTemplate())
{
return nullptr;
}
#endif
return Super::GetWorld();
}
The solution is to not call GetWorld on anything that doesn’t override it.
In the graph editor, IsTemplate()
is true
, so we return nullptr
and avoid the call to Super::GetWorld()
. While at runtime, with an instance of our class, we keep using the base class function to use some other outer object’s GetWorld
, if there’s one.
I avoid the call to IsTemplate()
on a packaged game because otherwise we’d traverse the chain of outer objects always twice.