UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
WidgetInteractionComponent.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#include "CoreMinimal.h"
8#include "InputCoreTypes.h"
9#include "Engine/HitResult.h"
12#include "Layout/WidgetPath.h"
13#include "WidgetInteractionComponent.generated.h"
14
16class UPrimitiveComponent;
18
23UENUM(BlueprintType)
38
39// TODO CenterScreen needs to be able to work with multiple player controllers, perhaps finding
40// the PC via the outer/owner chain? Maybe you need to set the PC that owns this? Maybe we should
41// key off the Virtual User Index?
42
43// TODO Expose modifier key state.
44
45// TODO Come up with a better way to let people forward a lot of keyboard input without a bunch of glue
46
48
55UCLASS(ClassGroup="UserInterface", meta=(BlueprintSpawnableComponent) , MinimalAPI)
56class UWidgetInteractionComponent : public USceneComponent
57{
59
60public:
65 UPROPERTY(BlueprintAssignable, Category="Interaction|Event")
66 FOnHoveredWidgetChanged OnHoveredWidgetChanged;
67
68public:
70
71 // Begin ActorComponent interface
72 UMG_API virtual void OnComponentCreated() override;
73 UMG_API virtual void Activate(bool bReset = false) override;
75 UMG_API virtual void TickComponent(float DeltaTime, enum ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override;
76 // End UActorComponent
77
83 UFUNCTION(BlueprintCallable, Category="Interaction")
84 UMG_API virtual void PressPointerKey(FKey Key);
85
91 UFUNCTION(BlueprintCallable, Category="Interaction")
92 UMG_API virtual void ReleasePointerKey(FKey Key);
93
99 UFUNCTION(BlueprintCallable, Category="Interaction")
100 UMG_API virtual bool PressKey(FKey Key, bool bRepeat = false);
101
105 UFUNCTION(BlueprintCallable, Category="Interaction")
106 UMG_API virtual bool ReleaseKey(FKey Key);
107
111 UFUNCTION(BlueprintCallable, Category="Interaction")
112 UMG_API virtual bool PressAndReleaseKey(FKey Key);
113
118 UFUNCTION(BlueprintCallable, Category="Interaction")
119 UMG_API virtual bool SendKeyChar(FString Characters, bool bRepeat = false);
120
124 UFUNCTION(BlueprintCallable, Category="Interaction")
125 UMG_API virtual void ScrollWheel(float ScrollDelta);
126
130 UFUNCTION(BlueprintCallable, Category="Interaction")
131 UMG_API UWidgetComponent* GetHoveredWidgetComponent() const;
132
137 UFUNCTION(BlueprintCallable, Category="Interaction")
138 UMG_API bool IsOverInteractableWidget() const;
139
144 UFUNCTION(BlueprintCallable, Category="Interaction")
145 UMG_API bool IsOverFocusableWidget() const;
146
151 UFUNCTION(BlueprintCallable, Category="Interaction")
152 UMG_API bool IsOverHitTestVisibleWidget() const;
153
157 UMG_API const FWeakWidgetPath& GetHoveredWidgetPath() const;
158
162 UFUNCTION(BlueprintCallable, Category="Interaction")
163 UMG_API const FHitResult& GetLastHitResult() const;
164
168 UFUNCTION(BlueprintCallable, Category="Interaction")
169 UMG_API FVector2D Get2DHitLocation() const;
170
174 UFUNCTION(BlueprintCallable, Category="Interaction")
175 UMG_API void SetCustomHitResult(const FHitResult& HitResult);
176
180 UFUNCTION(BlueprintCallable, Category = "Interaction")
181 UMG_API void SetFocus(UWidget* FocusWidget);
182
193
194public:
195
201 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Interaction", meta=( ClampMin = "0", ExposeOnSpawn = true ))
202 int32 VirtualUserIndex;
203
207 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Interaction", meta=( ClampMin = "0", UIMin = "0", UIMax = "9", ExposeOnSpawn = true ))
208 int32 PointerIndex;
209
210public:
211
215 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Interaction")
217
221 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Interaction")
222 float InteractionDistance;
223
229 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Interaction")
230 EWidgetInteractionSource InteractionSource;
231
238 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Interaction")
239 bool bEnableHitTesting;
240
241public:
242
246 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Debugging")
247 bool bShowDebug;
248
252 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Debugging", AdvancedDisplay, meta=( ClampMin = "0.001" ))
253 float DebugSphereLineThickness;
254
258 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Debugging", AdvancedDisplay, meta=( ClampMin = "0.001", ClampMax = "50"))
259 float DebugLineThickness;
260
264 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Debugging", AdvancedDisplay)
265 FLinearColor DebugColor;
266
268
269 // Gets the key and char codes for sending keys for the platform.
270 UMG_API void GetKeyAndCharCodes(const FKey& Key, bool& bHasKeyCode, uint32& KeyCode, bool& bHasCharCode, uint32& CharCode);
271
273 UMG_API bool CanSendInput();
274
276 UMG_API void SimulatePointerMovement();
277
279 {
281 : HitResult()
282 , LocalHitLocation(FVector2D::ZeroVector)
283 , HitWidgetComponent(nullptr)
284 , HitWidgetPath()
285 , bWasHit(false)
286 , LineStartLocation(FVector::ZeroVector)
287 , LineEndLocation(FVector::ZeroVector)
288 {
289 }
290
298 };
299
301 UMG_API virtual FWidgetPath FindHoveredWidgetPath(const FWidgetTraceResult& TraceResult) const;
302
304 UMG_API virtual FWidgetTraceResult PerformTrace() const;
305
310 UMG_API void GetRelatedComponentsToIgnoreInAutomaticHitTesting(TArray<UPrimitiveComponent*>& IgnorePrimitives) const;
311
313 UMG_API bool CanInteractWithComponent(UWidgetComponent* Component) const;
314
315protected:
316
319
322
325
328 FHitResult CustomHitResult;
329
332 FVector2D LocalHitLocation;
333
336 FVector2D LastLocalHitLocation;
337
339 UE_DEPRECATED(5.6, "Property deprecated, please use WeakHoveredWidgetComponent instead.")
341 TObjectPtr<UWidgetComponent> HoveredWidgetComponent = nullptr;
342
345 TWeakObjectPtr<UWidgetComponent> WeakHoveredWidgetComponent;
346
349 FHitResult LastHitResult;
350
353 bool bIsHoveredWidgetInteractable;
354
357 bool bIsHoveredWidgetFocusable;
358
361 bool bIsHoveredWidgetHitTestVisible;
362
363private:
364
365#if WITH_EDITOR
366 void OnPIEEnded(class UGameInstance*);
367#endif
368
370 FWidgetPath DetermineWidgetUnderPointer();
371
372private:
373#if WITH_EDITORONLY_DATA
374
376 UPROPERTY()
378
379#endif
380
381};
FPlatformTypes::int32 int32
A 32-bit signed integer.
Definition Platform.h:1125
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
#define DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams(DelegateName, Param1Type, Param1Name, Param2Type, Param2Name)
Definition DelegateCombinations.h:62
ELevelTick
Definition EngineBaseTypes.h:70
ECollisionChannel
Definition EngineTypes.h:1088
return true
Definition ExternalRpcRegistry.cpp:601
#define UPROPERTY(...)
UObject definition macros.
Definition ObjectMacros.h:744
#define GENERATED_BODY(...)
Definition ObjectMacros.h:765
#define UFUNCTION(...)
Definition ObjectMacros.h:745
#define UCLASS(...)
Definition ObjectMacros.h:776
#define UENUM(...)
Definition ObjectMacros.h:749
EWidgetInteractionSource
Definition WidgetInteractionComponent.h:25
uint8_t uint8
Definition binka_ue_file_header.h:8
uint32_t uint32
Definition binka_ue_file_header.h:6
Definition GenericApplication.h:75
Definition UObjectGlobals.h:1292
Definition UnrealType.h:3087
Definition SlateUser.h:18
Definition WidgetPath.h:213
Definition WidgetPath.h:51
Definition Array.h:670
Definition EnumAsByte.h:22
Definition SharedPointer.h:692
Definition GameInstance.h:152
Definition WidgetInteractionComponent.h:57
FModifierKeysState ModifierKeys
Definition WidgetInteractionComponent.h:321
FWeakWidgetPath LastWidgetPath
Definition WidgetInteractionComponent.h:318
TSet< FKey > PressedKeys
Definition WidgetInteractionComponent.h:324
Definition Widget.h:217
@ false
Definition radaudio_common.h:23
Definition EngineBaseTypes.h:571
Definition HitResult.h:21
Definition InputCoreTypes.h:50
Definition Color.h:48
Definition ObjectPtr.h:488
Definition WeakObjectPtrTemplates.h:25
Definition WidgetInteractionComponent.h:279
FVector LineEndLocation
Definition WidgetInteractionComponent.h:297
bool bWasHit
Definition WidgetInteractionComponent.h:295
FHitResult HitResult
Definition WidgetInteractionComponent.h:291
UWidgetComponent * HitWidgetComponent
Definition WidgetInteractionComponent.h:293
FVector2D LocalHitLocation
Definition WidgetInteractionComponent.h:292
FVector LineStartLocation
Definition WidgetInteractionComponent.h:296
FWidgetPath HitWidgetPath
Definition WidgetInteractionComponent.h:294
FWidgetTraceResult()
Definition WidgetInteractionComponent.h:280