Navigation
API > API/Runtime > API/Runtime/InteractiveToolsFramework
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
- in UpdateCapture()
- 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 | UInputBehavior |
| Type | class |
| Header File | /Engine/Source/Runtime/InteractiveToolsFramework/Public/InputBehavior.h |
| Include Path | #include "InputBehavior.h" |
Syntax
UCLASS (Transient, MinimalAPI)
class UInputBehavior : public UObject
Inheritance Hierarchy
- UObjectBase → UObjectBaseUtility → UObject → UInputBehavior
Derived Classes
UInputBehavior derived class hierarchy
Constructors
| Name | Remarks | Include Path | Unreal Specifiers |
|---|---|---|---|
UInputBehavior() |
InputBehavior.h |
Functions
Public
| Name | Remarks | Include Path | Unreal Specifiers |
|---|---|---|---|
virtual FInputCaptureUpdate BeginCapture
(
const FInputDeviceState& InputState, |
Called after WantsCapture() returns a capture request that was accepted | InputBehavior.h | |
virtual FInputCaptureUpdate BeginHoverCapture
(
const FInputDeviceState& InputState, |
Called after WantsHoverCapture() returns a capture request that was accepted | InputBehavior.h | |
virtual void EndHoverCapture() |
If a different hover capture begins, focus is lost, a tool starts, etc, any active hover visualization needs to terminate | InputBehavior.h | |
virtual void ForceEndCapture
(
const FInputCaptureData& CaptureData |
If this is called, the Behavior has forcibly lost capture (eg due to app losing focus for example) and needs to clean up accordingly | InputBehavior.h | |
virtual FInputCapturePriority GetPriority() |
The priority is used to resolve situations where multiple behaviors want the same capture | InputBehavior.h | |
virtual EInputDevices GetSupportedDevices() |
Which device types does this Behavior support | InputBehavior.h | |
virtual void SetDefaultPriority
(
const FInputCapturePriority& Priority |
Configure the default priority of an instance of this behavior | InputBehavior.h | |
virtual FInputCaptureUpdate UpdateCapture
(
const FInputDeviceState& InputState, |
Called for each new input event during a capture sequence. | InputBehavior.h | |
virtual FInputCaptureUpdate UpdateHoverCapture
(
const FInputDeviceState& InputState |
Called on each new hover input event, ie if no other behavior is actively capturing input | InputBehavior.h | |
virtual FInputCaptureRequest WantsCapture
(
const FInputDeviceState& InputState |
Given the input state, does this Behavior want to begin capturing some input devices? | InputBehavior.h | |
virtual bool WantsForceEndCapture () |
When this function returns true, this behavior will always receive ForceEndCapture calls even when it is not actively capturing. | InputBehavior.h | |
virtual FInputCaptureRequest WantsHoverCapture
(
const FInputDeviceState& InputState |
Given the input state, does this Behavior want to begin capturing some input devices for hover | InputBehavior.h | |
virtual bool WantsHoverEvents() |
Hover support (optional) return true if this Behavior supports hover (ie passive input events) | InputBehavior.h |