Download

Is there any way to get a list of streamed levels from a streaming volume?

I’m trying to assemble a map of level connections in my game, and the easiest way to do it seems to be by using the level streaming volumes I’ve already configured: if I can get a list of what level a volume loads, and what levels every volume that overlaps the first one loads, I instantly know that all of those levels can be physically reached from the first one.

The problem I’m running into is that ALevelStreamingVolume really doesn’t seem to be meant for this- looking through the source code I can run GetLevel() to find out which level the volume is in (this will always be the persistent level), I can use GetStreamingLevelNames to get the name of the level as an FName, but I don’t even see a centralized list holding references to what levels get streamed, much less a getter of some sort- is there an obvious route I’m missing here?

Wiki on Level Streaming

Hi there!

Check out LevelStreamingVolume.h

The first variable is a list of all levels affected by the streaming volume, as per your question!

:slight_smile:



UCLASS(hidecategories=(Advanced, Attachment, Collision, Volume), MinimalAPI)
class ALevelStreamingVolume : public AVolume
{
	GENERATED_UCLASS_BODY()

	**/** Levels names affected by this level streaming volume. */**
	UPROPERTY(Category=LevelStreamingVolume, VisibleAnywhere, BlueprintReadOnly, meta=(DisplayName = "Streaming Levels"))
	TArray<FName> StreamingLevelNames;



**Wiki**

Also have you seen my wiki on Level streaming?

**Streamed Levels, Test IfActor Is In Level Bounds**
https://wiki.unrealengine.com/Streamed_Levels,_Test_If_Actor_Is_In_Level_Bounds

This part of my code seems most relevant to your question:




```


//Print Name of current Level Streaming to know which level the unit is in!
ClientMessage( EachLevelStreaming->GetWorldAssetPackageName() );


```



This code lets you know** exactly which level a Level Streaming ptr is loading**, as per your question.

I'm using ClientMessage inside of player controller in this example to print message to console.

Entire C++ Code

Here’s the whole code, which iterates over all Level Streaming ptrs.

The usefulness of this code is that it lets you iterate over all levels that are currently loaded, regardless of where the volumes are and whose in them.

This direct-access method let’s you know at any time what the status of Level Streaming is, and which levels are loaded, in the entire UE4 World!



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

for(const ULevelStreaming* EachLevelStreaming : StreamedLevels)
{
	if( !EachLevelStreaming) 
	{
		continue;
	}
	
	ULevel* EachLevel =  EachLevelStreaming->GetLoadedLevel();
	
	//Is This Level Valid and Visible?
	if( !EachLevel || !EachLevel->bIsVisible) 
	{
		continue;
	}
		 
	//Print Name of current Level Streaming to know which level the unit is in!
	ClientMessage( EachLevelStreaming->GetWorldAssetPackageName() );
	  
	//Is the Player Location Within this Level's Bounds
	if(ALevelBounds::CalculateLevelBounds(EachLevel).IsInside(GetPawn()->GetActorLocation()))
	{
		ClientMessage("Yes Player Is Within This Level");
	}
}


Enjoy!

:slight_smile:

Rama

Rama this is excellent, you’ve answered every single one of my questions and a number I hadn’t thought to ask- thank you very much for the thoughtful and extremely comprehensive reply! :slight_smile:

Any way to do this in blueprints?