Hello I have problem with my HUD class. I have created c++ vehicle project and coded my custom HUD in c++ after which I have created Blueprint from my custom HUD class. The problem I have is that all everything which I coded in c++ works fine but whenever I want use my blueprint to add some visual scripting function nothing happen (I mean wont execute) I have set my game mode and HUD class in the editor. Maybe you guys can help me because I am stuck now.
Here is my HUD class code
UCLASS(config = Game)
class AVehicleHUD : public AHUD
{
GENERATED_UCLASS_BODY()
/** Font used to render the vehicle info */
UPROPERTY()
UFont* HUDFont;
public:
virtual void DrawHUD() override;
};
//.cpp
AVehicleHUD::AVehicleHUD(const class FPostConstructInitializeProperties& PCIP)
: Super(PCIP)
{
//Use font from the engine
static ConstructorHelpers::FObjectFinder<UFont> Font(TEXT("/Engine/EngineFonts/RobotoDistanceField"));
HUDFont = Font.Object;
}
void AVehicleHUD::DrawHUD()
{
//Draw HUD elements
}
I’ve implemented a fairly complicated C++ HUD which can be extended in blueprints. There are many ways to do it, but at the moment your DrawHUD() is not accessible to blueprints.
You have two choices:
Make it BlueprintCallable so that you can call the function from a blueprint.
To be clear the second version is not implemented in C++.
I have opted for both by doing this:
void ACustomHUD::OnReceiveDrawHUD(int32 SizeX, int32 SizeY)
{
// C++ code drawing the HUD
DrawHUD(SizeX, SizeY);
// BlueprintImplementableEvent which can optionally be implemented in blueprints to do additional work
OnHUDDrawCompleted(SizeX, SizeY);
}