Skip to main content

10 - UI HUD

A UUserWidget subclass that drives a HUD: widget bindables for data and BlueprintCallable helpers the widget graph uses.

Full source​

include "CoreMinimal.h"
include "Blueprint/UserWidget.h"

uclass AExampleHUD : UUserWidget meta: api=EXAMPLES_API
{
prop public float Health EditAnywhere BlueprintReadOnly category="HUD" default=100.0f
prop public float Ammo EditAnywhere BlueprintReadOnly category="HUD" default=30.0f
prop public bool bLowAmmo EditAnywhere BlueprintReadOnly category="HUD" default=false

method public virtual void NativeTick(const FGeometry& MyGeometry, float InDeltaTime) override {
Super::NativeTick(MyGeometry, InDeltaTime);
}

func public void SetHealth(float NewHealth) BlueprintCallable category="HUD"
{
Health = NewHealth;
}
}

Line by line​

  • uclass AExampleHUD : UUserWidget - a widget class (HUD).
  • prop public float Health ... BlueprintReadOnly - a bindable value a widget's Text value binding can read in the UMG designer.
  • prop public float Ammo ... BlueprintReadOnly - same for ammo.
  • prop public bool bLowAmmo ... BlueprintReadOnly - a flag the widget can bind to, e.g. to toggle a "reload" warning color.
  • method public virtual void NativeTick(...) override - per-frame widget tick (often you skip it; here it's an override example).
  • func public void SetHealth(float NewHealth) BlueprintCallable - a setter the widget graph (e.g. a Damage Taken event) calls; it updates the bindable, and the UMG binding re-renders the text.

The bindable → UI flow​

  1. Author a prop with BlueprintReadOnly.
  2. In UMG, create a Binding on a Text/ProgressBar.
  3. Select the bindable (e.g. Health).
  4. Any BlueprintCallable setter (like SetHealth) updates it; the widget re-binds next frame.

This keeps your HUD reactive with zero C++ UI code.

Next: 11 - Animation.