Loading screen

Hi
I try to create function for loading level with displaying UMG Widget. But I do not Widget on screen during loading of level.
Game is frozen and next loaded level appears.

ULoader* ULoader::DoLoad(TSubclassOf<UUserWidget> uWidget, FName loadLevel, FName unloadLevel, UObject* WorldContextObject, FLatentActionInfo LatentInfo)
{
if (UWorld* World = GEngine->GetWorldFromContextObject(WorldContextObject))
{
UUserWidget* Widget = nullptr;

if (uWidget)
{
Widget = CreateWidget<UUserWidget>(World, uWidget);
Widget->AddToViewport();
}
if (loadLevel.IsValid())
{
UGameplayStatics::LoadStreamLevel(World, loadLevel, true, false, LatentInfo);
}
if (uWidget)
{
Widget->RemoveFromParent();
}
if(unloadLevel.IsValid())
UGameplayStatics::UnloadStreamLevel(World, unloadLevel, LatentInfo);
}
return NULL;
}

But if I use blueprint then everything works ok.
Blueprint:

1 Like

I’ve not had the opportunity to dig into this area deeply yet, but I wonder about two things:

  1. Are you certain the C++ function you’re using is the correct one? Inadvertently using one that is invoked later than the one you intend would probably produce an effect like you are experiencing.
  2. Are you certain the level is being loaded asynchronously in both cases?

As a side note, if you’re working on Android, it looks like several others have run into similar issues. I’m not sure anyone has fully resolved them yet:

The last of these suggests that the problem these people have seen should be resolved in 4.10.x. I’ve not tested to be sure either way.

Regardless, they seem to have found a common workaround effective: A simple, static “loading” screen in one level that then loads the real level. You might be able to expand on that idea to either:

  • Stream your level in a few pieces to make the loading more responsive
  • Make the level more barebones and stream in the necessary content to fill it once the level and its UI have been loaded

I am working on PC game. I need to create load screen from Main Menu. When I click Start Game need to display load screen. I suppose in such situation streaming level is not good solution.