Download

Display my UMG UI made with Widget Blueprint

Hello everyone,

I’m new in UE4, I’m following this tutorial (https://docs.unrealengine.com/latest/INT/Engine/UMG/QuickStart/2/index.html) but I want currently to make my project with C++, and I don’t know how to display my HUD with C++.

Can you help me?
Thank you

You can start from something similar:



// Put this in the .h file. GameInstance, GameMode, HUD, PlayerController should be ok

    // You need a reference to a class of your UMG widget
    // You may setup the value of this property through blueprint
    UPROPERTY(EditDefaultsOnly, BlueprintReadonly)
    TSubclassOf<class UUserWidget> MyWidgetClass;

    // Then you need a place to store your created widget to show/hide it and garbage collector won't destroy it
    UPROPERTY()
    class UUserWidget* MyWidget;

// Put this in .cpp. In BeginPlay for example

    // Create the widget
    MyWidget = CreateWidget<UUserWidget>(GetWorld(), LoadingWidgetClass);

    // Display widget on screen
    MyWidget->AddToViewport();


In theory this should be enough.