Hello everyone. I have a C++ function in MyGameInstance
that loads a level then shows a UMG loading screen using MoviePlayer. It works, but shows an error in the logs:
Error Log
LogOutputDevice: Error: === Handled ensure: ===
LogOutputDevice: Error:
LogOutputDevice: Error: Ensure condition failed: GetShadowIndex() == 0 [File:D:\build\++UE5\Sync\Engine\Source\Runtime\Core\Public\HAL\IConsoleManager.h] [Line: 1610]
LogOutputDevice: Error:
LogOutputDevice: Error: Stack:
LogOutputDevice: Error: [Callstack] 0x00007ffd11b115f8 UnrealEditor-UMG.dll!UUserWidget::NativeTick() [D:\build\++UE5\Sync\Engine\Source\Runtime\UMG\Private\UserWidget.cpp:1854]
LogOutputDevice: Error: [Callstack] 0x00007ffd11b34596 UnrealEditor-UMG.dll!SObjectWidget::Tick() [D:\build\++UE5\Sync\Engine\Source\Runtime\UMG\Private\Slate\SObjectWidget.cpp:126]
LogOutputDevice: Error: [Callstack] 0x00007ffd1690b3b1 UnrealEditor-SlateCore.dll!SWidget::Paint() [D:\build\++UE5\Sync\Engine\Source\Runtime\SlateCore\Private\Widgets\SWidget.cpp:1445]
LogOutputDevice: Error: [Callstack] 0x00007ffd168d58af UnrealEditor-SlateCore.dll!SCompoundWidget::OnPaint() [D:\build\++UE5\Sync\Engine\Source\Runtime\SlateCore\Private\Widgets\SCompoundWidget.cpp:46]
LogOutputDevice: Error: [Callstack] 0x00007ffd1582b37b UnrealEditor-Slate.dll!SBorder::OnPaint() [D:\build\++UE5\Sync\Engine\Source\Runtime\Slate\Private\Widgets\Layout\SBorder.cpp:131]
LogOutputDevice: Error: [Callstack] 0x00007ffd1690bf1c UnrealEditor-SlateCore.dll!SWidget::Paint() [D:\build\++UE5\Sync\Engine\Source\Runtime\SlateCore\Private\Widgets\SWidget.cpp:1579]
LogOutputDevice: Error: [Callstack] 0x00007ffd168d7858 UnrealEditor-SlateCore.dll!SPanel::PaintArrangedChildren() [D:\build\++UE5\Sync\Engine\Source\Runtime\SlateCore\Private\Widgets\SPanel.cpp:34]
LogOutputDevice: Error: [Callstack] 0x00007ffd168d64da UnrealEditor-SlateCore.dll!SPanel::OnPaint() [D:\build\++UE5\Sync\Engine\Source\Runtime\SlateCore\Private\Widgets\SPanel.cpp:15]
LogOutputDevice: Error: [Callstack] 0x00007ffd1690bf1c UnrealEditor-SlateCore.dll!SWidget::Paint() [D:\build\++UE5\Sync\Engine\Source\Runtime\SlateCore\Private\Widgets\SWidget.cpp:1579]
LogOutputDevice: Error: [Callstack] 0x00007ffd168d637f UnrealEditor-SlateCore.dll!SOverlay::OnPaint() [D:\build\++UE5\Sync\Engine\Source\Runtime\SlateCore\Private\Widgets\SOverlay.cpp:209]
LogOutputDevice: Error: [Callstack] 0x00007ffd1690bf1c UnrealEditor-SlateCore.dll!SWidget::Paint() [D:\build\++UE5\Sync\Engine\Source\Runtime\SlateCore\Private\Widgets\SWidget.cpp:1579]
LogOutputDevice: Error: [Callstack] 0x00007ffd168d58af UnrealEditor-SlateCore.dll!SCompoundWidget::OnPaint() [D:\build\++UE5\Sync\Engine\Source\Runtime\SlateCore\Private\Widgets\SCompoundWidget.cpp:46]
LogOutputDevice: Error: [Callstack] 0x00007ffd1582b37b UnrealEditor-Slate.dll!SBorder::OnPaint() [D:\build\++UE5\Sync\Engine\Source\Runtime\Slate\Private\Widgets\Layout\SBorder.cpp:131]
LogOutputDevice: Error: [Callstack] 0x00007ffd1690bf1c UnrealEditor-SlateCore.dll!SWidget::Paint() [D:\build\++UE5\Sync\Engine\Source\Runtime\SlateCore\Private\Widgets\SWidget.cpp:1579]
LogOutputDevice: Error: [Callstack] 0x00007ffd168d7858 UnrealEditor-SlateCore.dll!SPanel::PaintArrangedChildren() [D:\build\++UE5\Sync\Engine\Source\Runtime\SlateCore\Private\Widgets\SPanel.cpp:34]
LogOutputDevice: Error: [Callstack] 0x00007ffd168d64da UnrealEditor-SlateCore.dll!SPanel::OnPaint() [D:\build\++UE5\Sync\Engine\Source\Runtime\SlateCore\Private\Widgets\SPanel.cpp:15]
LogOutputDevice: Error: [Callstack] 0x00007ffd1690bf1c UnrealEditor-SlateCore.dll!SWidget::Paint() [D:\build\++UE5\Sync\Engine\Source\Runtime\SlateCore\Private\Widgets\SWidget.cpp:1579]
LogOutputDevice: Error: [Callstack] 0x00007ffd168d637f UnrealEditor-SlateCore.dll!SOverlay::OnPaint() [D:\build\++UE5\Sync\Engine\Source\Runtime\SlateCore\Private\Widgets\SOverlay.cpp:209]
LogOutputDevice: Error: [Callstack] 0x00007ffd1690bf1c UnrealEditor-SlateCore.dll!SWidget::Paint() [D:\build\++UE5\Sync\Engine\Source\Runtime\SlateCore\Private\Widgets\SWidget.cpp:1579]
LogOutputDevice: Error: [Callstack] 0x00007ffd168d58af UnrealEditor-SlateCore.dll!SCompoundWidget::OnPaint() [D:\build\++UE5\Sync\Engine\Source\Runtime\SlateCore\Private\Widgets\SCompoundWidget.cpp:46]
LogOutputDevice: Error: [Callstack] 0x00007ffd158a6ce5 UnrealEditor-Slate.dll!SVirtualWindow::OnPaint() [D:\build\++UE5\Sync\Engine\Source\Runtime\Slate\Private\Widgets\SVirtualWindow.cpp:83]
LogOutputDevice: Error: [Callstack] 0x00007ffd1690bf1c UnrealEditor-SlateCore.dll!SWidget::Paint() [D:\build\++UE5\Sync\Engine\Source\Runtime\SlateCore\Private\Widgets\SWidget.cpp:1579]
LogOutputDevice: Error: [Callstack] 0x00007ffd3a6b53d9 UnrealEditor-MoviePlayer.dll!FMoviePlayerWidgetRenderer::DrawWindow() [D:\build\++UE5\Sync\Engine\Source\Runtime\MoviePlayer\Private\DefaultGameMoviePlayer.cpp:1026]
LogOutputDevice: Error: [Callstack] 0x00007ffd3a6c0c88 UnrealEditor-MoviePlayer.dll!FSlateLoadingSynchronizationMechanism::SlateThreadRunMainLoop() [D:\build\++UE5\Sync\Engine\Source\Runtime\MoviePlayer\Private\MoviePlayerThreading.cpp:170]
LogOutputDevice: Error: [Callstack] 0x00007ffd3a6bf4fc UnrealEditor-MoviePlayer.dll!FSlateLoadingThreadTask::Run() [D:\build\++UE5\Sync\Engine\Source\Runtime\MoviePlayer\Private\MoviePlayerThreading.cpp:211]
LogOutputDevice: Error: [Callstack] 0x00007ffd1bf3c0ad UnrealEditor-Core.dll!FRunnableThreadWin::Run() [D:\build\++UE5\Sync\Engine\Source\Runtime\Core\Private\Windows\WindowsRunnableThread.cpp:159]
LogOutputDevice: Error: [Callstack] 0x00007ffd1bf335cf UnrealEditor-Core.dll!FRunnableThreadWin::GuardedRun() [D:\build\++UE5\Sync\Engine\Source\Runtime\Core\Private\Windows\WindowsRunnableThread.cpp:79]
LogOutputDevice: Error: [Callstack] 0x00007ffd568a7374 KERNEL32.DLL!UnknownFunction []
LogOutputDevice: Error: [Callstack] 0x00007ffd5777cc91 ntdll.dll!UnknownFunction []
Here is the code:
MyGameInstance.h:
- This macro delays the execution of the program. Its purpose is to give time for texture streaming.
#define DELAY(time, block)\
{\
FTimerHandle TimerHandle;\
GetWorld()->GetTimerManager().SetTimer(TimerHandle, [&]()block, time, false);\
}
- This is the function that loads the level and shows UMG loading screen.
UFUNCTION(BlueprintCallable, meta = (WorldContext = WorldContextObject), Category = "Utility|LoadingScreen")
void LoadLevelWithLoadingScreen(const UObject* WorldContextObject, FName LevelName, bool bAbsolute, FString LevelOptions, TSubclassOf<class UUserWidget> LoadingScreenWidget, bool bUseMovies, TArray<FString> StringPaths, bool bUseAudio, USoundBase* SoundFile, float VolumeMultiplier);
- This function runs when level is loaded:
void OnLevelLoaded(UWorld* InLoadedWorld);
MyGameInstance.cpp:
void UMyGameInstance::LoadLevelWithLoadingScreen(const UObject* WorldContextObject, FName LevelName, bool bAbsolute, FString LevelOptions, TSubclassOf<class UUserWidget> LoadingScreenWidget, bool bUseMovies, TArray<FString> StringPaths, bool bUseAudio, USoundBase* SoundFile, float VolumeMultiplier)
{
if(!IsValid(WorldContextObject))
{
UE_LOG(LogTemp, Error, TEXT("WorldContext is not valid!"));
return;
}
UE_LOG(LogTemp, Warning, TEXT("WorldContextObject is valid."));
UWorld* World = WorldContextObject->GetWorld();
if(!IsValid(World))
{
UE_LOG(LogTemp, Error, TEXT("GetWorld for World is not valid!"));
return;
}
UE_LOG(LogTemp, Warning, TEXT("GetWorld is valid."));
UE_LOG(LogTemp, Warning, TEXT("GetMapName: %s"), *World->GetMapName());
FCoreUObjectDelegates::PostLoadMapWithWorld.AddUObject(this, &UMyGameInstance::OnLevelLoaded);
UE_LOG(LogTemp, Warning, TEXT("PostLoadMapWithWorld delegate has passed!"));
if(bUseAudio)
{
UGameplayStatics::SpawnSound2D(World, SoundFile, VolumeMultiplier, 1.0f, 0.0f, nullptr, true, false);
}
UGameplayStatics::OpenLevel(World, LevelName, bAbsolute, LevelOptions);
if(!IsRunningDedicatedServer())
{
UE_LOG(LogTemp, Warning, TEXT("We are not a dedicated server."));
UE_LOG(LogTemp, Warning, TEXT("GetMapName: %s"), *World->GetMapName());
FLoadingScreenAttributes LoadingScreen;
//LoadingScreen.bAllowEngineTick = true;
LoadingScreen.bAutoCompleteWhenLoadingCompletes = false;
LoadingScreen.bMoviesAreSkippable = false;
if(bUseMovies)
{
LoadingScreen.MoviePaths = StringPaths;
}
else
{
UUserWidget* Widget = CreateWidget<UUserWidget>(World, LoadingScreenWidget);
if(!IsValid(Widget))
{
UE_LOG(LogTemp, Error, TEXT("Widget to show in loading screen is not valid!"));
return;
}
LoadingScreen.WidgetLoadingScreen = Widget->TakeWidget();
GetMoviePlayer()->SetupLoadingScreen(LoadingScreen);
UE_LOG(LogTemp, Warning, TEXT("Showing loading screen successfully."));
}
}
}
void UMyGameInstance::OnLevelLoaded(UWorld* InLoadedWorld)
{
//this will trigger the code within the {} after a 2 second delay
DELAY(2.0,
{
if(GetMoviePlayer()->IsLoadingFinished())
{
GetMoviePlayer()->Shutdown();
}
})
}