Download

Is it possible to get a reference to ULevelStreamingVolume's level list in code?

I’ve been trying to read through ULevelStreaming.cpp, but I’m having a heck of a time figuring out how everything is hooked together and I’d really appreciate a little help navigating the source. In short, I’m trying to build a TMap<Ulevel*, TArray<Ulevel*>> in which each key is a single level in my game, and the corresponding value is every level the player (or NPC) can reach from the key level.

To actually determine how level connectivity works, I thought it made sense to use my level streaming volumes: if two level streaming volumes overlap each other, that means you can access the levels that one volume loads/unloads from the other volume. The following code is terrible and doesn’t actually compile, but I’m hoping it illustrates what I have in mind:



void CreateLevelMap(){

	TArray<ULevelStreamingVolume*> volumeList; //This holds references to every streaming volume the iterator will find in the persistent level

	TMap<ULevel*, TArray<ULevel*>> levelMap; //This will have one key for each level in the game, and a value of each intersecting level

	for (TObjectIterator<ULevelStreamingVolume> Itr; Itr; ++Itr) //Iterates through every level streaming volume in persistent level
	{
		volumeList.Add(&Itr); //Adds each volume to a list
	}

	for (int i = 0; i < volumeList.Num(); i++){
		TArray<ULevel*> currentLevel; //This is the level(s) volumeList* loads on overlap
		TArray<ULevel*> overlapLevels; //This is the level(s) every loading volume that overlaps currentLevel's volume load on overlap

		//Set both arrays, then...
		for (int j = 0; j < overlapLevels.Num(); j++){
			levelMap[currentLevel].Add(overlapLevels[j]); //Populate my LevelMap with TKey(Level), TValue (connecting levels) pairs of TArray<Ulevel*>
		}
	}
}

Where I could really use some help is figuring out how the heck to get references to a) which levels a ULevelStreamingVolume loads, and b) which levels they overlap. ULevelStreamingVolume.cpp is private, so I can’t even get the compiler to recognize that it’s a valid object, and since it’s a UObject, not an AActor, I can’t really use GetOverlappingActors to determine which volumes are overlapping which. Is this even a recommended way of going about this, or this an inadvisable approach?