I added “UMG”, “Slate”, “SlateCore” to PublicDependencyModuleNames
Added these includes to my .cpp include “Blueprint/UserWidget.h” include “CoreMinimal.h” include “UMG.h”
And this function is not working in my .cpp
UUserWidget* HUDWidget = CreateWidget(this, “WBP_HUD”);
Even though in my content browser is an UMG.UserWidget called “WBP_HUD” saved and compiled successfully.
Thats the live coding error
error C2672: ‘CreateWidget’: no matching overloaded function found
I already tried writing it like this Text(“WBP_HUD”) or just WBP_HUD
It is a widget blueprint though and the parent class is UMG.UserWidget. Is that the problem? Any workaround?
Class definitions are not magically parsed from the content browser. You must first load it into a class finder in your class’ constructor.
// .h file, somewhere inside your class definition.
UPROPERTY()
UClass* KeepThisUClass;
// .cpp file, includes.
#include "UObject/ConstructorHelpers.h"
// Class constructor
static ConstructorHelpers::FClassFinder<UUserWidget> MyWidgetClass(TEXT("/Game/Blueprints/Interfaces/WBP_HUD"));
if (MyWidgetClass.Class != NULL)
{
KeepThisUClass = MyWidgetClass.Class;
}
Then when its time to create your widget you must call it with your class definition.
// In some function in your class when you want to create it.
CreateWidget(this, KeepThisUClass, FName("Whatever you want as a personal name"));
What threw you off was probably the ‘Name’ part which is, in all of Unreal’s calling scheme, is always a personal name and not the name of an object or class or asset in the content browser. And in this case, it’s not even mandatory.
This is the template prototype for this function. As you can see, it doesn’t match what you wrote as a function.