Sorry, sorry, I know, I am asking too many questions. Consider it me catching up to the Unreal engine, which I should have done way earlier.
Anyways, as part of my ongoing quest of learning how to deal with C++ and UE4, I am now trying to add a HUD to my game. All the necessary information for UMG is already present within the game mode file.
The following code is based on a solution I found on the Unreal Answerhub, but when I implement it, it simply just crashes my editor. Immediately. Moving it to the BeginPlay (which I also tried), just makes it freeze the editor the moment I press play, so I reckon there’s something wrong on how I declared the class to begin with.
How do I go about attaching a widget to a HUD? To prevent having to setup the HUD in a level blueprint for every level, I want to have at least the initialization taking place within HUD class.
CPP
// Fill out your copyright notice in the Description page of Project Settings.
#include "MyGame.h"
#include "BK_HUDBase.h"
#include "BP_UIWidget_Minimap.h"
ABK_HUDBase::ABK_HUDBase(const FObjectInitializer& ObjectInitializer)
:Super(ObjectInitializer)
{
HUDMinimapClass = LoadClass<UBP_UIWidget_Minimap>(NULL, NULL, TEXT("This/Is/A/Path/TestMiniMap.TestMiniMap'"), LOAD_None, NULL);
HUDMinimap = CreateWidget<UBP_UIWidget_Minimap>(GetWorld(), HUDMinimapClass);
HUDMinimap->AddToViewport();
}
void ABK_HUDBase::BeginPlay()
{
}
H
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "GameFramework/HUD.h"
#include "BP_UIWidget_Minimap.h"
#include "BK_HUDBase.generated.h"
/**
*
*/
UCLASS()
class MYGAME_API ABK_HUDBase : public AHUD
{
GENERATED_BODY()
ABK_HUDBase(const FObjectInitializer& ObjectInitializer);
TSubclassOf<class UBP_UIWidget_Minimap> HUDMinimapClass;
UBP_UIWidget_Minimap* HUDMinimap;
virtual void BeginPlay() override;
};
I have a feeling it has to do with one of the other 4 parameters of LoadClass, since I only knew what to fill in for 1 of them.
Bonus question How do I go about changing the resolution size of the widget? Preferably, I want to spit up the HUD into various parts, since that would be easier to maintain for what I am planning. That, or learning how to mask the contents of widgets would be awesome. Since I am building a minimap, it would be annoying if visual indicators could slip beyond the borders of the minimap.