How to get current world?

doesn’t have a reference to any actor

and without that reference, how are you going to tell the engine which world you want?

currently active world

There is the possibility of multiple World instances existing at the same time. You need something to provide the context for which World instance you want. There isn’t a “currently active World”.

There’s GEngine->GetWorldFromContextObject() to retrieve the World from static, but without a UObject that clearly exists in a specific World instance, you’re not able to use that. And with your solution, you’re not necessarily guaranteed to get the World instance that you want. (other than PIE, I’m not sure what other conditions can cause there to be multiple Worlds, but it is possible)

This is usually resolved by passing in the ‘this’ of whatever is making the call, as the context object for GetWorldFromContextObject.

3 Likes