Choose your operating system:
Windows
macOS
Linux
Module |
|
Header |
/Engine/Source/Runtime/InteractiveToolsFramework/Public/InputBehavior.h |
Include |
#include "InputBehavior.h" |
class UInputBehavior : public UObject
An InputBehavior implements a state machine for a user interaction. The InputRouter maintains a set of active Behaviors, and when new input events occur, it calls WantsCapture() to check if the Behavior would like to begin capturing the applicable input event stream (eg for a mouse, one or both VR controllers, etc). If the Behavior acquires capture, UpdateCapture() is called until the Behavior indicates that it wants to release the device, or until the InputRouter force-terminates the capture via ForceEndCapture().
For example, something like ButtonSetClickBehavior might work as follows:
in WantsCapture(), if left mouse is pressed and a button is under cursor, return Begin, otherwise Ignore
in BeginCapture(), save identifier for button that is under cursor
if left mouse is down, return Continue
if left mouse is released:
if saved button is still under cursor, call button.Clicked()
return End
Written sufficiently generically, the above Behavior doesn't need to know about buttons, it just needs to know how to hit-test the clickable object(s). Similarly separate Behaviors can be written for mouse, VR, touch, gamepad, etc.
Implementing interactions in this way allows the input handling to be separated from functionality.
Name | Description | ||
---|---|---|---|
|
DefaultPriority |
Priority returned by GetPriority() |
Name | Description | |
---|---|---|
|
UInputBehavior() |
Name | Description | ||
---|---|---|---|
|
FInputCaptur... |
BeginCapture ( |
Called after WantsCapture() returns a capture request that was accepted |
|
FInputCaptur... |
BeginHoverCapture ( |
Called after WantsHoverCapture() returns a capture request that was accepted |
|
EndHoverCapture() |
If a different hover capture begins, focus is lost, a tool starts, etc, any active hover visualization needs to terminate |
|
|
ForceEndCapture ( |
If this is called, the Behavior has forcibly lost capture (eg due to app losing focus for example) and needs to clean up accordingly |
|
|
FInputCaptur... |
GetPriority() |
The priority is used to resolve situations where multiple behaviors want the same capture |
|
EInputDevice... |
GetSupportedDevices() |
Which device types does this Behavior support |
|
SetDefaultPriority ( |
Configure the default priority of an instance of this behavior |
|
|
FInputCaptur... |
UpdateCapture ( |
Called for each new input event during a capture sequence. |
|
FInputCaptur... |
UpdateHoverCapture ( |
Called on each new hover input event, ie if no other behavior is actively capturing input |
|
FInputCaptur... |
WantsCapture ( |
Given the input state, does this Behavior want to begin capturing some input devices? |
|
FInputCaptur... |
WantsHoverCapture ( |
Given the input state, does this Behavior want to begin capturing some input devices for hover |
|
WantsHoverEvents() |
Hover support (optional)return true if this Behavior supports hover (ie passive input events) |