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