UWidgetComponent
Inherits: UObjectBase › UObjectBaseUtility › UObject › UActorComponent › USceneComponent › UPrimitiveComponent › UMeshComponent › UWidgetComponent
#include "Components/WidgetComponent.h" Description
A component that renders a UUserWidget in the 3D world. Supports both World space (rendered as a mesh surface in the scene) and Screen space (rendered as a 2D overlay always facing the camera).
Signature
class UWidgetComponent : public UMeshComponent Caveats & Gotchas
- • World-space widgets can be occluded by geometry and receive lighting. Screen-space widgets are drawn in a post-process pass and are never occluded.
- • The widget is rendered to a UTextureRenderTarget2D each frame — this has a GPU cost. Disable tick on components not actively changing to save performance.
- • Interaction with World-space widget components requires UWidgetInteractionComponent — regular mouse/touch input does not hit them.
Example
Attach a world-space health bar to an enemy C++
HealthBarComponent = CreateDefaultSubobject<UWidgetComponent>(TEXT("HealthBar"));
HealthBarComponent->SetupAttachment(RootComponent);
HealthBarComponent->SetWidgetClass(UMyHealthBarWidget::StaticClass());
HealthBarComponent->SetWidgetSpace(EWidgetSpace::World);
HealthBarComponent->SetDrawSize(FVector2D(200.f, 40.f)); See Also
Tags
Version History
Introduced in: 4.5
| Version | Status | Notes |
|---|---|---|
| 5.6 | stable | — |
Feedback
Was this helpful?