Launch a Blueprint Widget from C++ code

Okay, so, at this point I have most of that – I have a UUserWidget called ‘Examine’ and a Blueprint based off that called ‘NewWidgetBlueprint’ what I want to do is set it so that when I press a key and trigger the above Take() method ‘NewWidgetBlueprint’ pops up. I’d rather keep that triggering in C++ (if possible) because the Take() method does a few other things.

I’ve been trying variations on this code in the Take method:

FStringClassReference MyWidgetClassRef(TEXT("/Game/NewWidgetBlueprint.NewWidgetBlueprint"));
		UClass* MyWidgetClass = MyWidgetClassRef.TryLoadClass<UExamine>();
		UExamine *widget = CreateWidget<UExamine>(()->GetFirstPlayerController(), MyWidgetClass);
		widget->AddToViewport();

But no joy so far. Any thoughts?

1 Like