Skip to content

Instantly share code, notes, and snippets.

@PapeCoding
Created March 9, 2020 15:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PapeCoding/df0e1619fc2911efcafff8375bdbb202 to your computer and use it in GitHub Desktop.
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
// 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);
@PapeCoding
Copy link
Author

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/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment