UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
UWidgetInteractionComponent Class Reference

#include <WidgetInteractionComponent.h>

+ Inheritance diagram for UWidgetInteractionComponent:

Classes

struct  FWidgetTraceResult
 

Public Member Functions

UMG_API UWidgetInteractionComponent (const FObjectInitializer &ObjectInitializer=FObjectInitializer::Get())
 
virtual UMG_API void OnComponentCreated () override
 
virtual UMG_API void Activate (bool bReset=false) override
 
virtual UMG_API void Deactivate () override
 
virtual UMG_API void TickComponent (float DeltaTime, enum ELevelTick TickType, FActorComponentTickFunction *ThisTickFunction) override
 
virtual UMG_API void PressPointerKey (FKey Key)
 
virtual UMG_API void ReleasePointerKey (FKey Key)
 
virtual UMG_API bool PressKey (FKey Key, bool bRepeat=false)
 
virtual UMG_API bool ReleaseKey (FKey Key)
 
virtual UMG_API bool PressAndReleaseKey (FKey Key)
 
virtual UMG_API bool SendKeyChar (FString Characters, bool bRepeat=false)
 
virtual UMG_API void ScrollWheel (float ScrollDelta)
 
UMG_API UWidgetComponentGetHoveredWidgetComponent () const
 
UMG_API bool IsOverInteractableWidget () const
 
UMG_API bool IsOverFocusableWidget () const
 
UMG_API bool IsOverHitTestVisibleWidget () const
 
UMG_API const FWeakWidgetPathGetHoveredWidgetPath () const
 
UMG_API const FHitResultGetLastHitResult () const
 
UMG_API FVector2D Get2DHitLocation () const
 
UMG_API void SetCustomHitResult (const FHitResult &HitResult)
 
UMG_API void SetFocus (UWidget *FocusWidget)
 

Public Attributes

FOnHoveredWidgetChanged OnHoveredWidgetChanged
 
int32 VirtualUserIndex
 
int32 PointerIndex
 
TEnumAsByte< ECollisionChannelTraceChannel
 
float InteractionDistance
 
EWidgetInteractionSource InteractionSource
 
bool bEnableHitTesting
 
bool bShowDebug
 
float DebugSphereLineThickness
 
float DebugLineThickness
 
FLinearColor DebugColor
 

Protected Member Functions

UMG_API void GetKeyAndCharCodes (const FKey &Key, bool &bHasKeyCode, uint32 &KeyCode, bool &bHasCharCode, uint32 &CharCode)
 
UMG_API bool CanSendInput ()
 
UMG_API void SimulatePointerMovement ()
 
virtual UMG_API FWidgetPath FindHoveredWidgetPath (const FWidgetTraceResult &TraceResult) const
 
virtual UMG_API FWidgetTraceResult PerformTrace () const
 
UMG_API void GetRelatedComponentsToIgnoreInAutomaticHitTesting (TArray< UPrimitiveComponent * > &IgnorePrimitives) const
 
UMG_API bool CanInteractWithComponent (UWidgetComponent *Component) const
 

Protected Attributes

TSharedPtr< FSlateVirtualUserHandleVirtualUser
 
FWeakWidgetPath LastWidgetPath
 
FModifierKeysState ModifierKeys
 
TSet< FKeyPressedKeys
 
FHitResult CustomHitResult
 
FVector2D LocalHitLocation
 
FVector2D LastLocalHitLocation
 
TObjectPtr< UWidgetComponentHoveredWidgetComponent = nullptr
 
TWeakObjectPtr< UWidgetComponentWeakHoveredWidgetComponent
 
FHitResult LastHitResult
 
bool bIsHoveredWidgetInteractable
 
bool bIsHoveredWidgetFocusable
 
bool bIsHoveredWidgetHitTestVisible
 

Detailed Description

This is a component to allow interaction with the Widget Component. This class allows you to simulate a sort of laser pointer device, when it hovers over widgets it will send the basic signals to show as if the mouse were moving on top of it. You'll then tell the component to simulate key presses, like Left Mouse, down and up, to simulate a mouse click.

Constructor & Destructor Documentation

◆ UWidgetInteractionComponent()

UWidgetInteractionComponent::UWidgetInteractionComponent ( const FObjectInitializer ObjectInitializer = FObjectInitializer::Get())

Member Function Documentation

◆ Activate()

void UWidgetInteractionComponent::Activate ( bool  bReset = false)
overridevirtual

◆ CanInteractWithComponent()

bool UWidgetInteractionComponent::CanInteractWithComponent ( UWidgetComponent Component) const
protected

Returns true if the inteaction component can interact with the supplied widget component

◆ CanSendInput()

bool UWidgetInteractionComponent::CanSendInput ( )
protected

Is it safe for this interaction component to run? Might not be in a server situation with no slate application.

◆ Deactivate()

void UWidgetInteractionComponent::Deactivate ( )
overridevirtual

◆ FindHoveredWidgetPath()

FWidgetPath UWidgetInteractionComponent::FindHoveredWidgetPath ( const FWidgetTraceResult TraceResult) const
protectedvirtual

Gets the WidgetPath for the widget being hovered over based on the hit result.

◆ Get2DHitLocation()

FVector2D UWidgetInteractionComponent::Get2DHitLocation ( ) const

Gets the last hit location on the widget in 2D, local pixel units of the render target.

◆ GetHoveredWidgetComponent()

UWidgetComponent * UWidgetInteractionComponent::GetHoveredWidgetComponent ( ) const

Get the currently hovered widget component.

◆ GetHoveredWidgetPath()

const FWeakWidgetPath & UWidgetInteractionComponent::GetHoveredWidgetPath ( ) const

Gets the widget path for the slate widgets under the last hit result.

◆ GetKeyAndCharCodes()

void UWidgetInteractionComponent::GetKeyAndCharCodes ( const FKey Key,
bool bHasKeyCode,
uint32 KeyCode,
bool bHasCharCode,
uint32 CharCode 
)
protected

◆ GetLastHitResult()

const FHitResult & UWidgetInteractionComponent::GetLastHitResult ( ) const

Gets the last hit result generated by the component. Returns the custom hit result if that was set.

◆ GetRelatedComponentsToIgnoreInAutomaticHitTesting()

void UWidgetInteractionComponent::GetRelatedComponentsToIgnoreInAutomaticHitTesting ( TArray< UPrimitiveComponent * > &  IgnorePrimitives) const
protected

Gets the list of components to ignore during hit testing. Which is everything that is a parent/sibling of this component that's not a Widget Component. This is so traces don't get blocked by capsules and such around the player.

◆ IsOverFocusableWidget()

bool UWidgetInteractionComponent::IsOverFocusableWidget ( ) const

Returns true if a widget under the hit result is focusable. e.g. Slate widgets that return true for SupportsKeyboardFocus().

◆ IsOverHitTestVisibleWidget()

bool UWidgetInteractionComponent::IsOverHitTestVisibleWidget ( ) const

Returns true if a widget under the hit result is has a visibility that makes it hit test visible. e.g. Slate widgets that return true for GetVisibility().IsHitTestVisible().

◆ IsOverInteractableWidget()

bool UWidgetInteractionComponent::IsOverInteractableWidget ( ) const

Returns true if a widget under the hit result is interactive. e.g. Slate widgets that return true for IsInteractable().

◆ OnComponentCreated()

void UWidgetInteractionComponent::OnComponentCreated ( )
overridevirtual

◆ PerformTrace()

UWidgetInteractionComponent::FWidgetTraceResult UWidgetInteractionComponent::PerformTrace ( ) const
protectedvirtual

Performs the trace and gets the hit result under the specified InteractionSource

◆ PressAndReleaseKey()

bool UWidgetInteractionComponent::PressAndReleaseKey ( FKey  Key)
virtual

Does both the press and release of a simulated keyboard key.

◆ PressKey()

bool UWidgetInteractionComponent::PressKey ( FKey  Key,
bool  bRepeat = false 
)
virtual

Press a key as if it had come from the keyboard. Avoid using this for 'a-z|A-Z', things like the Editable Textbox in Slate expect OnKeyChar to be called to signal a specific character being send to the widget. So for those cases you should use SendKeyChar.

◆ PressPointerKey()

void UWidgetInteractionComponent::PressPointerKey ( FKey  Key)
virtual

Presses a key as if the mouse/pointer were the source of it. Normally you would just use Left/Right mouse button for the Key. However - advanced uses could also be imagined where you send other keys to signal widgets to take special actions if they're under the cursor.

◆ ReleaseKey()

bool UWidgetInteractionComponent::ReleaseKey ( FKey  Key)
virtual

Releases a key as if it had been released by the keyboard.

◆ ReleasePointerKey()

void UWidgetInteractionComponent::ReleasePointerKey ( FKey  Key)
virtual

Releases a key as if the mouse/pointer were the source of it. Normally you would just use Left/Right mouse button for the Key. However - advanced uses could also be imagined where you send other keys to signal widgets to take special actions if they're under the cursor.

◆ ScrollWheel()

void UWidgetInteractionComponent::ScrollWheel ( float  ScrollDelta)
virtual

Sends a scroll wheel event to the widget under the last hit result.

◆ SendKeyChar()

bool UWidgetInteractionComponent::SendKeyChar ( FString  Characters,
bool  bRepeat = false 
)
virtual

Transmits a list of characters to a widget by simulating a OnKeyChar event for each key listed in the string.

◆ SetCustomHitResult()

void UWidgetInteractionComponent::SetCustomHitResult ( const FHitResult HitResult)

Set custom hit result. This is only taken into account if InteractionSource is set to EWidgetInteractionSource::Custom.

◆ SetFocus()

void UWidgetInteractionComponent::SetFocus ( UWidget FocusWidget)

Set the focus target of the virtual user managed by this component

◆ SimulatePointerMovement()

void UWidgetInteractionComponent::SimulatePointerMovement ( )
protected

Performs the simulation of pointer movement. Does not run if bEnableHitTesting is set to false.

◆ TickComponent()

void UWidgetInteractionComponent::TickComponent ( float  DeltaTime,
enum ELevelTick  TickType,
FActorComponentTickFunction ThisTickFunction 
)
overridevirtual

Member Data Documentation

◆ bEnableHitTesting

bool UWidgetInteractionComponent::bEnableHitTesting

Should the interaction component perform hit testing (Automatic or Custom) and attempt to simulate hover - if you were going to emulate a keyboard you would want to turn this option off if the virtual keyboard was separate from the virtual pointer device and used a second interaction component.

◆ bIsHoveredWidgetFocusable

bool UWidgetInteractionComponent::bIsHoveredWidgetFocusable
protected

Are we hovering over any focusable widget?

◆ bIsHoveredWidgetHitTestVisible

bool UWidgetInteractionComponent::bIsHoveredWidgetHitTestVisible
protected

Are we hovered over a widget that is hit test visible?

◆ bIsHoveredWidgetInteractable

bool UWidgetInteractionComponent::bIsHoveredWidgetInteractable
protected

Are we hovering over any interactive widgets.

◆ bShowDebug

bool UWidgetInteractionComponent::bShowDebug

Shows some debugging lines and a hit sphere to help you debug interactions.

◆ CustomHitResult

FHitResult UWidgetInteractionComponent::CustomHitResult
protected

Stores the custom hit result set by the player.

◆ DebugColor

FLinearColor UWidgetInteractionComponent::DebugColor

Determines the color of the debug lines.

◆ DebugLineThickness

float UWidgetInteractionComponent::DebugLineThickness

Determines the thickness of the debug lines.

◆ DebugSphereLineThickness

float UWidgetInteractionComponent::DebugSphereLineThickness

Determines the line thickness of the debug sphere.

◆ HoveredWidgetComponent

TObjectPtr<UWidgetComponent> UWidgetInteractionComponent::HoveredWidgetComponent = nullptr
protected

DEPRECATED - Use WeakHoveredWidgetComponent instead

◆ InteractionDistance

float UWidgetInteractionComponent::InteractionDistance

The distance in game units the component should be able to interact with a widget component.

◆ InteractionSource

EWidgetInteractionSource UWidgetInteractionComponent::InteractionSource

Should we project from the world location of the component? If you set this to false, you'll need to call SetCustomHitResult(), and provide the result of a custom hit test form whatever location you wish.

◆ LastHitResult

FHitResult UWidgetInteractionComponent::LastHitResult
protected

The last hit result we used.

◆ LastLocalHitLocation

FVector2D UWidgetInteractionComponent::LastLocalHitLocation
protected

The last 2D location on the widget component that was hit.

◆ LastWidgetPath

FWeakWidgetPath UWidgetInteractionComponent::LastWidgetPath
protected

The last widget path under the hit result.

◆ LocalHitLocation

FVector2D UWidgetInteractionComponent::LocalHitLocation
protected

The 2D location on the widget component that was hit.

◆ ModifierKeys

FModifierKeysState UWidgetInteractionComponent::ModifierKeys
protected

The modifier keys to simulate during key presses.

◆ OnHoveredWidgetChanged

FOnHoveredWidgetChanged UWidgetInteractionComponent::OnHoveredWidgetChanged

Called when the hovered Widget Component changes. The interaction component functions at the Slate level - so it's unable to report anything about what UWidget is under the hit result.

◆ PointerIndex

int32 UWidgetInteractionComponent::PointerIndex

Each user virtual controller or virtual finger tips being simulated should use a different pointer index.

◆ PressedKeys

TSet<FKey> UWidgetInteractionComponent::PressedKeys
protected

The current set of pressed keys we maintain the state of.

◆ TraceChannel

TEnumAsByte<ECollisionChannel> UWidgetInteractionComponent::TraceChannel

The trace channel to use when tracing for widget components in the world.

◆ VirtualUser

TSharedPtr<FSlateVirtualUserHandle> UWidgetInteractionComponent::VirtualUser
protected

Represents the virtual user in slate. When this component is registered, it gets a handle to the virtual slate user it will be, so virtual slate user 0, is probably real slate user 8, as that's the first index by default that virtual users begin - the goal is to never have them overlap with real input hardware as that will likely conflict with focus states you don't actually want to change - like where the mouse and keyboard focus input (the viewport), so that things like the player controller receive standard hardware input.

◆ VirtualUserIndex

int32 UWidgetInteractionComponent::VirtualUserIndex

Represents the Virtual User Index. Each virtual user should be represented by a different index number, this will maintain separate capture and focus states for them. Each controller or finger-tip should get a unique PointerIndex.

◆ WeakHoveredWidgetComponent

TWeakObjectPtr<UWidgetComponent> UWidgetInteractionComponent::WeakHoveredWidgetComponent
protected

The widget component we're currently hovering over.


The documentation for this class was generated from the following files: