Created
March 9, 2020 15:28
-
-
Save PapeCoding/df0e1619fc2911efcafff8375bdbb202 to your computer and use it in GitHub Desktop.
This allows the spawning of a widget from C++, which is then attached to the viewport
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Declare this in Header | |
TSubclassOf<class UUserWidget> Overlay_Class; | |
UUserWidget* Overlay; | |
// Do this in Constructor | |
ConstructorHelpers::FClassFinder<UUserWidget> WidgetClassFinder(TEXT("WidgetBlueprint'/MyPlugin/MyWidgetName'")); | |
if (WidgetClassFinder.Succeeded()) | |
{ | |
Overlay_Class = WidgetClassFinder.Class; | |
} | |
else | |
{ | |
UE_LOG(LogCalibratio, Error, TEXT("Could not find the Overlay class. Have you renamed it?")); | |
} | |
//Do this in BeginPlay | |
Overlay = CreateWidget<UUserWidget>(GetWorld()->GetFirstPlayerController(), Overlay_Class); | |
Overlay->AddToViewport(0); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This can also be used with an own widget C++ class, from which your UMG Blueprint class inherits. For this, replace every
UUserWidget
with your C++ class name.For more information on C++ widget collaboration with UMG Blueprints read http://benhumphreys.ca/unreal/ui-bindwidget/