Download

Unloading Levels via C++ Bug/Error

It works perfectly but only unloads the first level it finds? Yet in the log i can clear see it ran 3 times…?



const TArray<ULevelStreaming*>& StreamedLevels = GetWorld()->StreamingLevels;

	for (const ULevelStreaming* EachLevelStreaming : StreamedLevels)
	{
		if (!EachLevelStreaming)
		{
			continue;
		}

		GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Black, EachLevelStreaming->GetWorldAssetPackageName());
		FString Test = EachLevelStreaming->GetWorldAssetPackageName();
		GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Yellow, Test);
		Test.RemoveFromStart(FString("/game/maps/testmaps/uedpie_0_"), ESearchCase::IgnoreCase);
		Test.RemoveFromStart(FString("/temp/autosaves/Game/Maps/TestMaps/UEDPC"), ESearchCase::IgnoreCase);
		FName ConvertedFString = FName(*Test);
		int32 i = 256;
		i++;
		FLatentActionInfo info;
		info.UUID = i;

		//info.CallbackTarget = *myObjectWithDerivesFromUObject;
		info.ExecutionFunction = "myFunctionToCall";
		info.Linkage = 0;
		UGameplayStatics::UnloadStreamLevel(GetWorld(), ConvertedFString, FLatentActionInfo());
		UE_LOG(LogClass, Log, TEXT("UnloadStreamLevel!"));
		
		ULevel* EachLevel = EachLevelStreaming->GetLoadedLevel();
		
		//Is This Level Valid and Visible?
		if (!EachLevel || !EachLevel->bIsVisible)
		{
			continue;
		}
		

		//UGameplayStatics::LoadStreamLevel(this, FName(*MapName*), true, true, info);
		//FName("Streaming_test_B_")
		//GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Blue, EachLevelStreaming->GetName());
		//GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Black, EachLevel->GetName());
		//SaveGameInstance->SaveLevelsActive->AddUnique(EachLevel);
	}


25d1c4d845a849a99844a07c97488987.jpg

nvm solved it =)