Streaming Level loaded from a Pak File

flo.rian_zh
Fri, 25 Oct 2024 03:51:07 +0000
C++

Hi all, I have some questions and problems when streaming a level loaded from a pak file. What I basically wan’t to achieve is that another developer can create a pak file with any level in it and my game can load and unload this level. I don’t know if this is the best way to achive this but currently I am doing the following:

// Mount pak
PakFileHelper->MountAndRegisterPak(PakFilePath

// List levels in pak
TArray<FString> LevelsInPak = PakFileSubsystem->GetPakLevelContent(PakFilePath);

// Reload asset registry to load assets from pak file
FAssetRegistryModule& AssetRegistryModule = FModuleManager::LoadModuleChecked<FAssetRegistryModule>("AssetRegistry");
AssetRegistryModule.Get().ScanPathsSynchronous({"/Game/"}, true);

// Stream Level
bool bOutSuccess = false;
ULevelStreamingDynamic* LevelStreaming = ULevelStreamingDynamic::LoadLevelInstance(
	GetWorld(),
	LevelsInPak[0],
	FVector::ZeroVector,
	FRotator::ZeroRotator,
	bOutSuccess);

// Check level streamed load status
if (bOutSuccess)
{
	// Load level to scene
	LevelStreaming->SetShouldBeLoaded(true);
	LevelStreaming->SetShouldBeVisible(true);
}

The loading in the editor actually works fine and I can succesfully see the level in the scene. Altough I don’t know why I have to reload the asset registry. Other similar solutions didn’t had to do this, but it doesn’t work without it.
However if I end the simulation or if I unload the streamed level, the whole editor crashes with the following error:

Error        LogWindows                appError called: Assertion failed: LevelStreaming || GetActorCount() [File:D:\build\++UE5\Sync\Engine\Source\Runtime\Engine\Private\WorldPartition\WorldPartitionRuntimeLevelStreamingCell.cpp] [Line: 630]

I tried looking into the source code but I didn’t quite understand what they are doing there. Also note that this is only the case if I play the game in the editor. If I run a packaged version of the game the unloading works totally fine.

However in the packaged version of the game there is another problem with loading the level. In the editor the loaded level looks totally fine. Here is an example (really basic):

In the packaged game the same loaded pak level looks the following:

So my question mostly is if there is anything I am doing wrong here because some things only work in the editor and some things only work in the packaged game. Also with the crashes in the simulation this is really annoying to test so there has to be a better way of doing this.

Note that there are some other errors logs, which happen without any action while playing the game so I don’t know if it’s related to thisbut I’ll attach a full log just in case:
Full Log of play in editor (Streaming level from pak, then ending the simulation) (click for more details)
Any help would be grately appreciated!

3 posts - 3 participants