So I first cache the level with LoadPackageAsync(), store the package and world as UProperties, then call UGameplayStatics::OpenLevel. Which seems to be working, except none of the sublevels (using world composition) are being loaded.
For debugging purposes I am printing out all streaming levels in the BeginPlay() of my game mode with GetWorld()->StreamingLevels. When starting the level in PIE all the levels are there, when loading asynchronously the list is empty.
I have encountered a new problem: UWorld::RefreshStreamingLevels() seems to only work in PIE, which is weird, so I tried calling the FlushLevelStreaming() function directly. But this one also seems to load the streamed levels in PIE, not in standalone. Is this expected behaviour? Is there any way of making it work outside of PIE?
Edit:
The UWorld::StreamingLevels array is empty in standalone, need to figure out why
For future reference: After level loading, if you want to make sure all of your streaming levels (or your world composition) are fully loaded, you can check like this:
for (ULevelStreaming* StreamingLevel : World->StreamingLevels)
{
if (StreamingLevel->IsStreamingStatePending())
{
return false; // This means not fully loaded. You can build a loop with a delay in your BP for consecutive checks
}
}
Async loading is working only when game is cooked and proper setting is enabled in project settings, see FAsyncLoadingThread::ShouldBeMultithreaded().
I have asked UE devs to please address this as this is very annoying not to have async behavior during development.
Thank you for the solution, there is no chance I could find it myself. In my case World Composition worked well in PIE (except the loading delay) but not in Standalone game, it just didn’t try to load anything.
By the way, did you find a root cause?