Skip to content

Instantly share code, notes, and snippets.

@looterz looterz/README.md
Last active May 22, 2019

Embed
What would you like to do?
UE4 Loading Screen with Progress

This will only work in cooked builds with Event Driven Loader enabled (enabled by default). Currently this only shows the specified packages loading progress, but not dependant packages, which is an annoying issue since that is where most of the loading time is for maps.

#include "TestGameInstance.h"
#include "MoviePlayer/Public/MoviePlayer.h"
#include "Widgets/SCompoundWidget.h"
#include "Widgets/Text/STextBlock.h"
#include "Widgets/SBoxPanel.h"
class STestLoadingScreen : public SCompoundWidget
{
public:
SLATE_BEGIN_ARGS(STestLoadingScreen)
: _InMap()
{}
SLATE_ARGUMENT(FName, InMap)
SLATE_END_ARGS()
void Construct(const FArguments& InArgs)
{
InMap = InArgs._InMap;
ChildSlot
[
SNew(SVerticalBox)
+ SVerticalBox::Slot()
.VAlign(VAlign_Center)
.HAlign(HAlign_Center)
[
SNew(STextBlock)
.Font(FCoreStyle::GetDefaultFontStyle("Regular", 64))
.Text(this, &STestLoadingScreen::GetMessage)
.Visibility(this, &STestLoadingScreen::GetMessageIndicatorVisibility)
]
];
}
private:
FName InMap;
FText GetMessage() const
{
float LoadPercentage = GetAsyncLoadPercentage(InMap);
if (LoadPercentage < 0)
{
LoadPercentage = 100.f;
}
return FText::FromString(FString::Printf(TEXT("%d%%"), FMath::TruncToInt(LoadPercentage)));
}
EVisibility GetMessageIndicatorVisibility() const
{
return EVisibility::Visible;
}
};
void UTestGameInstance::Init()
{
Super::Init();
FCoreUObjectDelegates::PreLoadMap.AddUObject(this, &UTestGameInstance::BeginLoadingScreen);
}
void UTestGameInstance::BeginLoadingScreen(const FString& MapName)
{
if (IsRunningDedicatedServer())
{
return;
}
FLoadingScreenAttributes LoadingScreen;
LoadingScreen.bAutoCompleteWhenLoadingCompletes = false;
LoadingScreen.bWaitForManualStop = false;
LoadingScreen.bMoviesAreSkippable = false;
LoadingScreen.WidgetLoadingScreen = SNew(STestLoadingScreen).InMap(FName(*MapName));
LoadingScreen.PlaybackType = EMoviePlaybackType::MT_LoadingLoop;
GetMoviePlayer()->SetupLoadingScreen(LoadingScreen);
GetMoviePlayer()->PlayMovie();
}
#pragma once
#include "Test.h"
#include "CoreMinimal.h"
#include "Engine/GameInstance.h"
#include "TestGameInstance.generated.h"
UCLASS(config=Game)
class TEST_API UTestGameInstance : public UGameInstance
{
GENERATED_BODY()
public:
virtual void Init() override;
void BeginLoadingScreen(const FString& MapName);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.