Displaying a quote from each NPC dialog box
To display a dialog box, we need a custom (heads-up display) HUD. In the UE4 editor, go to File | Add Code To Project... and choose the HUD
class from which the subclass is created. Name your subclass as you wish; I've named mine MyHUD
.
After you have created the MyHUD
class, let Visual Studio reload. We will make some code edits.
Displaying messages on the HUD
Inside the AMyHUD
class, we need to implement the DrawHUD()
function in order to draw our messages to the HUD and to initialize a font to draw to the HUD with, as shown in the following code:
UCLASS() class GOLDENEGG_API AMyHUD : public AHUD { GENERATED_UCLASS_BODY() // The font used to render the text in the HUD. UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = HUDFont) UFont* hudFont; // Add this function to be able to draw to the HUD! virtual void DrawHUD() override; };
The HUD font will be set in a blueprinted version of the AMyHUD
class. The DrawHUD()
function runs...