I needed a simple function to unload all levels, but something went wrong...

.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.

Sorry, I’m stupid. :roll_eyes:

One of the levels I was trying to unload was the owner of an actor that had this level unload function inside its blueprint.

I just forgot that it needs to be moved to a persistent level.