Greetings.
I got a way to create an UMG widget from code:
Additional Info:
This method just works on PIE and with an offset from mouse coordinates (this widget should store a custom mouse cursor).
On Standalone launchs the widget doesn't show at all, I've checked the Player0 Viewport Size and it's zeroed XY.
I'm calling the method from AGameMode::StartPlay(), what I thought is the same as make the creation and call from the Game Blueprint.
Thoughts? Tips?
I got a way to create an UMG widget from code:
Code:
//On my HUD class I have a pointer to a widget: UMyWidgetClass * MyWidgetPointer: void AMyHUD::AddUMGWidgetToScreen() { if (UMyWidgetClass == nullptr) { UClass * MyWidgetLoadedClass; // Creates a class FString WidgetBPAddress = "/Game/Somedir/Somedir/WIDGETBP.WIDGETBP"; UBlueprint * WidgetBP; WidgetBP = Cast<UBlueprint>(StaticLoadObject(UBlueprint::StaticClass(), NULL, *WidgetBPAddress, NULL, LOAD_None, NULL)); check(WidgetBP) { MyWidgetLoadedClass = WidgetBP->GeneratedClass; MyWidgetPointer = CreateWidget<UMyWidgetClass>(GetWorld()->GetFirstPlayerController(), MyWidgetClass); MyWidgetPointer->AddToViewport(); } } }
Additional Info:
This method just works on PIE and with an offset from mouse coordinates (this widget should store a custom mouse cursor).
On Standalone launchs the widget doesn't show at all, I've checked the Player0 Viewport Size and it's zeroed XY.
I'm calling the method from AGameMode::StartPlay(), what I thought is the same as make the creation and call from the Game Blueprint.
Thoughts? Tips?
Comment