C++ Streaming level Error

Minty597
Fri, 17 Feb 2023 10:45:36 +0000
C++

Hi All

Im trying to stream some level files using the following code

for (FAssetData	Asset : AssetData)
	{
		FStaticConstructObjectParameters params(ULevelStreamingDynamic::StaticClass());
		params.Outer = GetWorld();
		params.Name = NAME_None;
		params.SetFlags = RF_NoFlags;
		params.InternalSetFlags = EInternalObjectFlags::None;

		ULevelStreamingDynamic* StreamingLevel = static_cast<ULevelStreamingDynamic*>( StaticConstructObject_Internal(params));

		// Associate a package name.
		StreamingLevel->SetWorldAssetByPackageName(Asset.AssetName);
		if (GetWorld()->IsPlayInEditor())
		{
			FWorldContext WorldContext = GEngine->GetWorldContextFromWorldChecked(GetWorld());
			StreamingLevel->RenameForPIE(WorldContext.PIEInstance);
		}

		StreamingLevel->LevelColor = FColor::MakeRandomColor();
		StreamingLevel->SetShouldBeLoaded(true);
		StreamingLevel->SetShouldBeVisible(true);
		StreamingLevel->bShouldBlockOnLoad = false;
		StreamingLevel->bInitiallyLoaded = true;
		StreamingLevel->bInitiallyVisible = true;

		FTransform A{
			FRotator{},                 // Rotation
			FVector{1.0f, 2.0f, 3.0f},  // Translation
			FVector{2.0f, 2.0f, 2.0f}   // Scale
		};

		StreamingLevel->LevelTransform = A; // where to put it

		StreamingLevel->PackageNameToLoad =Asset.PackageName; // PackageName containing level to load

		UE_LOG(LogLevelGen, Warning, TEXT("trying to loadlevel %s"), *StreamingLevel->PackageNameToLoad.ToString());


		FString PackageFileName;
		if( !FPackageName::DoesPackageExist( StreamingLevel->PackageNameToLoad.ToString(), &PackageFileName ) )
		{
			UE_LOG(LogLevelGen, Error, TEXT("trying to load invalid level %s"), *StreamingLevel->PackageNameToLoad.ToString());
			return ;
		}

		StreamingLevel->PackageNameToLoad = FName(*FPackageName::FilenameToLongPackageName(PackageFileName));

		// Add the new level to world.
		GetWorld()->AddStreamingLevel(StreamingLevel );
	}

when I run the code, I get the following errors
LogLevelStreaming: Warning: Streaming Level ‘/Game/UEDPIE_0_CPPTest.CPPTest:LevelStreamingDynamic_2’ uses same destination for level (‘’) as ‘/Game/UEDPIE_0_CPPTest.CPPTest:LevelStreamingDynamic_0’. Level cannot be loaded again and this StreamingLevel will be flagged as failed to load.

LogLevelStreaming: Warning: Streaming Level ‘/Game/UEDPIE_0_CPPTest.CPPTest:LevelStreamingDynamic_1’ uses same destination for level (‘’) as ‘/Game/UEDPIE_0_CPPTest.CPPTest:LevelStreamingDynamic_0’. Level cannot be loaded again and this StreamingLevel will be flagged as failed to load.

What do they mean?
How do I set the Destination?

1 post - 1 participant