Hello, i was trying to add my widget to the viewport and get the following error, All seem to work but i dont see the widget in screen, i have verified if the widget is successfully add with “isInViewport” and it return true.
Cpp
#include "GameInstance_Global.h"
#include "Blueprint/UserWidget.h"
#include "Engine/GameEngine.h"
void UGameInstance_Global::Init() {
Super::Init();
FCoreUObjectDelegates::PreLoadMap.AddUObject(this,&UGameInstance_Global::PreLoadMap);
FCoreUObjectDelegates::PostLoadMapWithWorld.AddUObject(this,&UGameInstance_Global::PostLoadMap);
}
void UGameInstance_Global::PreLoadMap(const FString & MapName) {
GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::Yellow, TEXT("Loading map"));
LoadingScreen = CreateWidget<UUserWidget>(this, LoadingWidget);
if (LoadingScreen) {
GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::Yellow, TEXT("Created"));
LoadingScreen->AddToViewport();
if (LoadingScreen->IsInViewport()) {
GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::Yellow, TEXT("Added To Viewport"));
}
}
}
void UGameInstance_Global::PostLoadMap(UWorld* world) {
}
.H
#include "CoreMinimal.h"
#include "Engine/GameInstance.h"
#include "GameInstance_Global.generated.h"
/**
*
*/
UCLASS()
class MULTIPLAYERGAME_API UGameInstance_Global : public UGameInstance
{
GENERATED_BODY()
virtual void Init() override;
UFUNCTION()
virtual void PreLoadMap(const FString & MapName);
UFUNCTION()
virtual void PostLoadMap(UWorld* world);
public:
UUserWidget * LoadingScreen;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Widget")
TSubclassOf<class UUserWidget> LoadingWidget;
};
And of course i selected my widget in the gameinstance blueprint