Simple load freeze fix

I don’t know if the loading screen is addressed in later lectures, but for now instead of the game unexpectedly freezing when it loads the map, I found a simple way to make the UI draw a load screen first.

To do this I simply binded one of the text widgets to c++ , then told the host function to change the text of this widget, (called a UTextBlock, inherited from Components/TextBlock.h )
using the function SetText , as so:

UPROPERTY(meta = (BindWidget))
class UTextBlock* TitleTextMainMenu;
> void UMainMenu::HostServer()
> {
> 	bflagHostServer = true;
> 	if (TitleTextMainMenu != nullptr)
> 	{
> 		TitleTextMainMenu->SetText(FText::FromString("Loading"));
> 	}
> }

I then moved the Server Travel function into the UWidget tick method; which is as follows
virtual void NativeTick(const FGeometry & MyGeometry, float InDeltaTime) override;

void UMainMenu::NativeTick(const FGeometry & MyGeometry, float InDeltaTime) 
{
	Super::Tick(MyGeometry,InDeltaTime);
	if (bflagHostServer == true) {
		if (MainMenuInterface != nullptr)
		{
			MainMenuInterface->Host();
		}
		bflagHostServer = false;
	}
}

I then added a bool to flag to the tick method it is ready to change maps, so when the Host method is called it can change the Text of the Title to “Loading”, and this text will actually be visible, since the frame will update before it runs NativeTick again

This could be incorporated in similar ways for different temporary load screens

Very nice workaround. I don’t think it was fixed in the lectures so thanks for sharing.

I think there might be some asynchronous versions of the level loading function to allow you to display a proper load bar as well.

1 Like

I’d like to know more about these asynchronous functions/overloads; I’m having trouble finding information on them.
(not sure if they even exist)

There are some very long videos that seem to be about blueprints … :thinking:

Loading screens may not be the easiest thing.
Will have to look into this again later.

I think the way to do it is through streaming levels with UGameplayStatics::LoadStreamLevel. That way the level is loading in the background and you can get a notification when it’s done to hide the UI.

1 Like

Oh man, I hope I go back to this forum when I get to this part of the course!

1 Like

Privacy & Terms