No announcement yet.

Hud c++

  • Filter
  • Time
  • Show
Clear All
new posts

    Hud c++

    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
    /** Font used to render the vehicle info */
    UFont* HUDFont;
    virtual void DrawHUD() override;
    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:rawHUD()
    //Draw HUD elements

    Hi there.

    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:

    1. Make it BlueprintCallable so that you can call the function from a blueprint.

    UFUNCTION(BlueprintCallable, Category = HUD)
    void DrawHUD();
    Then you can implement DrawHUD() in C++, but call it from a blueprint.

    2. Make it a BlueprintImplementableEvent which you can implement and call in blueprints.

    UFUNCTION(BlueprintImplementableEvent, Category = HUD)
    void DrawHUD();
    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);