Don't use map names that differ only by a prefix

The following Unreal Gotcha burned us on our current project, so just in case someone else hits this I’m putting the situation up here. We were doing a Halloween version of our Impossible Travel Agency VR project, and we made a second set of maps that all had the HAL_ prefix on them. Then, based on which button you hit in the menu, it would stream load the appropriate set of maps for the normal or Halloween version of the game. This worked great in the editor, but failed in the packaged build. You always got the Halloween version of the maps, even though you hit the normal button. We tracked this into the load level node, which even when given the normal name was loading the wrong file. This is the culprit:

ULevelStreaming* FStreamLevelAction::FindAndCacheLevelStreamingObject( const FName LevelName, UWorld* InWorld )
{
	// Search for the level object by name.
	if( LevelName != NAME_None )
	{
		const FString SearchPackageName = MakeSafeLevelName( LevelName, InWorld );

		for (ULevelStreaming* LevelStreaming : InWorld->StreamingLevels)
		{
			// We check only suffix of package name, to handle situations when packages were saved for play into a temporary folder
			// Like Saved/Autosaves/PackageName
			if (LevelStreaming && 
				LevelStreaming->GetWorldAssetPackageName().EndsWith(SearchPackageName, ESearchCase::IgnoreCase))
			{
				return LevelStreaming;
			}
		}
	}

	return NULL;
}  

It will return the first level it finds that ends with the string you passed it. So if your level names differ only by a prefix it will return the wrong one for one map or the other, depending on the order they’re in the list. It’s apparently intentional, since they’re trying to handle the directory portion being different in temp folders, but they probably should have stripped the path before doing the test instead of just checking “EndsWith.”

Hopefully this will save someone else some pain.

Rick

Ah. OK, I screwed up. ITA is still building in 4.12, our next is using 4.13. Looking at the code for 4.13 it looks like they fixed it. Sorry for the false alarm.

Hey

This was a known issue that was reported in 4.12.4 and appears to have been fixed in 4.13 (Unreal Engine Issues and Bug Tracker (UE-32956) ). If you are still seeing the issue of your streaming levels getting the wrong map based on similar names, can you provide as much information as possible to help us investigate why this is still occurring?

Additionally, can you let me know if adding “/” when package name is a short name has any affect for you? Specifically, let me know if adding the following if statement between lines 6 & 8 helps any with how your level names are being .

if (FPackageName::IsShortPackageName(SearchPackageName))
{
	// Make sure MyMap1 and Map1 names do not resolve to a same streaming level
	SearchPackageName = TEXT("/") + SearchPackageName;
}