How do I add my own widget to this loading screen system?

Ive been racking my brain trying to make a a proper loading screen system and came across This tutorial on the wiki
However I cannot figure out how to use my onw widget blueprint instead of “NewTestLoadingScreen”

I am very very new to C++ so im not sure where to even begin. I assume I need to create a C++ class to use as the parent for my Widget Blueprint, make a reference to it in the game instance file and then somehow call it.

Here is my code for my Game Instance C++ file

include “BP_ShiverPineGI.h”
include “MoviePlayer.h”
include “Blueprint/UserWidget.h” // Include the UserWidget header
include “W_LoadingScreen_P.h” // Include the header for your custom loading screen widget

void UBP_ShiverPineGI::Init()
{
Super::Init();

FCoreUObjectDelegates::PreLoadMap.AddUObject(this, &UBP_ShiverPineGI::BeginLoadingScreen);
FCoreUObjectDelegates::PostLoadMapWithWorld.AddUObject(this, &UBP_ShiverPineGI::EndLoadingScreen);

}

void UBP_ShiverPineGI::BeginLoadingScreen(const FString& InMapName)
{
if (!IsRunningDedicatedServer())
{
FLoadingScreenAttributes LoadingScreen;

    LoadingScreen.bAutoCompleteWhenLoadingCompletes = false;

    LoadingScreen.WidgetLoadingScreen = FLoadingScreenAttributes::NewTestLoadingScreenWidget();

    GetMoviePlayer()->SetupLoadingScreen(LoadingScreen);
}

}

void UBP_ShiverPineGI::EndLoadingScreen(UWorld* InLoadedWorld)
{

}

header file

// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "CoreMinimal.h"
#include "Engine/GameInstance.h"
#include "Blueprint/UserWidget.h" 
#include "MyGameInstance.generated.h"

/**
 * 
 */
UCLASS()
class LSCREENTEST_API UMyGameInstance : public UGameInstance
{
	GENERATED_BODY()

public:
    virtual void Init() override;

    UFUNCTION()
    virtual void BeginLoadingScreen(const FString& MapName);
    UFUNCTION()
    virtual void EndLoadingScreen(UWorld* InLoadedWorld);

    UPROPERTY(EditAnywhere, BlueprintReadWrite)
    TSubclassOf<UUserWidget> LoadingWidget;

};

cpp file

// Fill out your copyright notice in the Description page of Project Settings.


#include "MyGameInstance.h"
#include "GameFramework/PlayerController.h" 
#include "Kismet/GameplayStatics.h"
#include "MoviePlayer.h"

void UMyGameInstance::Init()
{
    Super::Init();

    FCoreUObjectDelegates::PreLoadMap.AddUObject(this, &UMyGameInstance::BeginLoadingScreen);
    FCoreUObjectDelegates::PostLoadMapWithWorld.AddUObject(this, &UMyGameInstance::EndLoadingScreen);
}

void UMyGameInstance::BeginLoadingScreen(const FString& InMapName)
{
    if (!IsRunningDedicatedServer())
    {
        FLoadingScreenAttributes LoadingScreen;
        LoadingScreen.bAutoCompleteWhenLoadingCompletes = false;
        LoadingScreen.WidgetLoadingScreen = FLoadingScreenAttributes::NewTestLoadingScreenWidget();
        /*
        LoadingScreen.MinimumLoadingScreenDisplayTime(-1.0f);
        LoadingScreen.bAutoCompleteWhenLoadingCompletes(true);
        LoadingScreen.bMoviesAreSkippable(true);
        //LoadingScreen.bWaitForManualStop(false) {}
        */
                
        if (LoadingWidget != nullptr) {
            UUserWidget* LoadingWidgetInstance = CreateWidget<UUserWidget>(this, LoadingWidget);            
            LoadingScreen.WidgetLoadingScreen = LoadingWidgetInstance->TakeWidget();
        }
        
        GetMoviePlayer()->SetupLoadingScreen(LoadingScreen);
    }
}

void UMyGameInstance::EndLoadingScreen(UWorld* InLoadedWorld)
{

}

Be sure to make a blueprint GameInstance based on UMyGameInstance and inside of it set the LoadingWidget parameter.

Set the BP GameInstance in the project settings.

OFC set your own project api for the file

LscreenTest.zip (24.8 MB)

1 Like

Thanks! that worked!

I have one more question, is it possible to only call the loading screen when I desire (in blueprints) as a function? because as of right now its tied to the delegates and spawns every time a level is opened. Sometimes I don’t want a loading screen.

LscreenTest_updated.zip (24.9 MB)

Updated the project to allow manual and auto loading screens.
Take into account it’s just an enforced widget. You will have to add in logic like disabling the using input and setting the correct z-index of the widget to make sure it covers all other widgets.

Would have uploaded sooner but the manual widget was being garbage collected between loads and would cause a crash on the removefromparent check.