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.
-
-
Save mikalv/6584a7b14e23bc54ad3cd102c9be8988 to your computer and use it in GitHub Desktop.
UE4 Loading Screen with Progress
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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