How to add Blueprint Widget HUD to C++ GameMode?

I have a Blueprint HUD…

WidgetBlueprint'/Game/UI/GameHUD.GameHUD'

And a C++ GameMode…

Class'/Script/Trek_On.Trek_OnGameMode'

The GameMode is as follows:

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

#pragma once

#include "GameFramework/GameMode.h"
#include "Trek_OnGameMode.generated.h"

class AEnemy;

UCLASS()
class TREK_ON_API ATrek_OnGameMode : public AGameMode
{
	GENERATED_BODY()
	
public:

	// Constructor
	ATrek_OnGameMode();

	// Array of current enemies
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Enemies")
		TArray<AEnemy *> Enemies;
};

And…

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

#include "Trek_On.h"
#include "Enterprise.h"
#include "Trek_OnGameMode.h"
#include "GameFramework/HUD.h"

ATrek_OnGameMode::ATrek_OnGameMode()
{
	static ConstructorHelpers::FObjectFinder<UClass> HUDFinder(
		TEXT("WidgetBlueprint'/Game/UI/GameHUD.GameHUD'"));

	DefaultPawnClass = AEnterprise::StaticClass();
	HUDClass = (UClass *) HUDFinder.Object;
}

I’m getting the following error and my HUD is not showing up.

Error: CDO Constructor (Trek_OnGameMode): Failed to find WidgetBlueprint'/Game/UI/GameHUD.GameHUD'

I’ve changed this line:

	static ConstructorHelpers::FObjectFinder<UClass> HUDFinder(
		TEXT("WidgetBlueprint'/Game/UI/GameHUD.GameHUD_C'"));

And I now no longer get the CDO error, but my HUD still isn’t showing up…

You should use UWidgetBlueprint instead of UClass and then from Object you call GetBlueprintClass() to get UClass*

ATrek_OnGameMode::ATrek_OnGameMode()
{
static ConstructorHelpers::FObjectFinder HUDFinder(
TEXT(“WidgetBlueprint’/Game/UI/GameHUD.GameHUD_C’”));

	DefaultPawnClass = AEnterprise::StaticClass();

	HUDClass = HUDFinder.Object->GetBlueprintClass();
}

I’m getting a “UWidgetBlueprint” is undefined, do I need to include something?

Hmmm this belongs to UMGEditor which is editor module which you can’t distribute, try UBlueprint insted, it’s base class of UWidgetBlueprint, in main engine module

error C2039: ‘GetBlueprintClass’ : is not a member of ‘UBlueprint’

Thats wierd it should be there:

Hey,

Any success ? I’m bumping into the same problem.

Thanks

Cedric