Command "MAP REBUILD ALLVISIBLE" with Hidden Sublevels Causes Fatal Log On Level Change

Hi just calling to attention a bug with this command “MAP REBUILD ALLVISIBLE” when there are hidden sublevels on the current map. Initially we found it when changing maps after building lighting and traced it through a BSP actor being present and triggering “MAP REBUILD ALLVISIBLE” in EditorBuildUtils.cpp.

Locally we have fixed it by changing UWorld::ReInitWorld() to track hidden levels and re-add them back in. Do you see any issues with this fix?

	CleanupWorld();
	// Grab hidden levels about to be removed
	TArray<TObjectPtr<class ULevel>> HiddenLevels;
	for (auto Level : Levels)
	{
		if (Level && !Level->bIsVisible)
		{
			HiddenLevels.Add(Level);
		}
	}
	// This clears UWorld::Levels
	InitWorld(IVS);
	// this only considers visible ULevels, leaving hidden ULevels now dangling
	RefreshStreamingLevels();
	// restore hidden ULevels back into UWorld::Levels
	for (auto Level : HiddenLevels)
	{
		AddLevel(Level);
	}
	UpdateWorldComponents(false /* bRerunConstructionScripts */, false /* bCurrentLevelOnly */);
}



Steps to Reproduce
Have reproduced it in UE5.6. Reproduction instructions are.

  1. Create empty project
  2. Create three levels
    1. LevelA
    2. LevelAHidden
    3. LevelB
  3. Open LevelA and add LevelBHidden as a hidden sublevel
  4. Run “MAP REBUILD ALLVISIBLE”
  5. Open LevelB

Hello [mention removed]​,

Thanks for the report. I was able to reproduce the issue locally in UE 5.5, 5.6 and also in a recent source build from the Main P4 stream (CL 45195475). I’ve submitted this as an engine bug in Epic’s JIRA so the team can handle this issue.

You will be able to track the status of the bug in the following link: Unreal Engine Issues and Bug Tracker (UE\-316382)

Please note that Epic ultimately determines whether the issue will be made publicly accessible and the process may take a few days. The tracking link might not work immediately.

In the meantime, your workaround looks appropriate and works in the latest build I tested as well.

I’ll go ahead and close the case now but feel free to reply if you have anything else to add.

Best,

Francisco