Adding a custom HUD and drawing a cross hair

No first person character perspective is complete without a small cross hair to denote the center of the screen. Let's create one now by making a custom code HUD. Using the C++ class wizard, create a code object that inherits from HUD called BMHUD.

BMHUD class definition

Now, navigate to BMHUD.h. All we need to do here is override the DrawHUD() method so we can define custom HUD functionality, define a default constructor, and add a UTexture2D handle to hold the crosshair image we are going to use. This can be done with the following code:

UCLASS() class BOSSMODE_API ABMHUD : public AHUD { GENERATED_BODY() public: ABMHUD(); /** Primary draw call for the HUD */ virtual void DrawHUD() override; private: ...

Get Unreal Engine 4.X By Example now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.