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: /** Crosshair asset pointer */ class UTexture2D* CrosshairTex; };
Defining the BMHUD
First off, we need to populate the UTexture2D
handle with an appropriate asset. We will do this in the default constructor. Add the following...