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 looterz/27d3fff244d0669b499bc057a913fb16 to your computer and use it in GitHub Desktop.
#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); | |
}; |
How can I make this work in my project?
Implement your own GameInstance class in the project and set it up like the one in this gist. I ended up moving away from trying to display load progress because of issues related to tracking dependent package loading progress with this method, so it's not accurate enough to be really useful. I haven't tested this in a couple of years though, could be fixed, as long as they updated GetAsyncLoadProgress to track dependent package loading progress too.
It won't work now because FAsyncLoadingThread2::GetAsyncLoadPercentage
will always return -1.0f, unfortunately. Overall, these techniques won't work with World Partition either, the only more or less reliable technique is to count actors being registered and update the list when the next ULevelStreaming
is loaded. But it's very tricky.
How can I make this work in my project?