UWidgetComponent HUD does not keep consistent screen size when zooming / changing distance – how to fix?

Hi everyone,

I’m working on an RTS-style project in UE5 where each regiment actor has a floating HUD using a UWidgetComponent.

Here is how I set it up:

HUDWidget = CreateDefaultSubobject<UWidgetComponent>(TEXT("HUDWidget"));
HUDWidget->SetupAttachment(RootComponent);
HUDWidget->SetWidgetSpace(EWidgetSpace::Screen); // or World depending on tests
HUDWidget->SetRelativeLocation(FVector(0.f, 0.f, 250.f));
HUDWidget->SetDrawSize(FVector2D(200.f, 60.f));
HUDWidget->SetDrawAtDesiredSize(true);

The widget is a UUserWidget (URegimentHUD) containing progress bars and a text label.


Problem

I want the HUD to:

  • always appear the same size on screen

  • regardless of:

    • camera distance

    • zoom level

    • camera rotation

Right now, the widget’s perceived size changes depending on how far the camera is or how much I zoom in/out.


Question

What is the correct way to make a UWidgetComponent behave like a true screen-space HUD element, while still being attached to a world actor?

I want it to stay anchored above the unit but maintain a constant screen size like UI/HUD elements.


What I already tried

  • SetWidgetSpace(EWidgetSpace::Screen)

  • SetDrawAtDesiredSize(true)

  • adjusting SetDrawSize(...)

But I still can’t get consistent screen-size behavior.


Context

This is for an RTS system with many units, each showing health and morale bars above their formation.

set the widget component to screen space, that is the whole trick: HUDWidget->SetWidgetSpace(EWidgetSpace::Screen). screen space draws the widget at Draw Size in viewport pixels, so distance and zoom dont change how big it looks. world space projects it in 3D, which is why it grows and shrinks with the camera.
turn Draw At Desired Size off in this case, it only makes sense for world space widgets. if you ever need a world space one at a fixed screen size, you have to scale it by distance yourself.