.h
/** Unload all streamed levels */
UFUNCTION(BlueprintCallable, meta = (WorldContext = "WorldContextObject", DisplayName = "Unload All Streaming Levels"), Category = "MaG BPFL_LevelManager")
static void UnloadAllStreamedLevels(const UObject* WorldContextObject, bool& Success);
.cpp
void UBPFL_LevelManager::UnloadAllStreamedLevels(const UObject* WorldContextObject, bool& Success)
{
if (UWorld* World = GEngine->GetWorldFromContextObject(WorldContextObject, EGetWorldErrorMode::LogAndReturnNull))
{
auto StreamedLevels = World->GetStreamingLevels();
for (ULevelStreaming* StreamedLevel : StreamedLevels)
{
if (StreamedLevel && StreamedLevel->IsLevelLoaded())
{
FLatentActionInfo LatentInfo;
UGameplayStatics::UnloadStreamLevel(WorldContextObject, StreamedLevel->GetWorldAssetPackageFName(), LatentInfo, false);
}
}
}
}
For some reason, after this function, the next latent function is executed, but does not transfer control.
Example1:
Example2:
Green - good, red - not executing.