Contents

InputTargetComponent

A component that gives an entity the ability to receive system input.

Declaration

struct InputTargetComponent

Overview

This component should be added to an entity to inform the system that it should be treated as a target for input handling. It can be customized to require only specific forms of input like direct or indirect interactions. By default the component is configured to handle all forms of input on the system.

The hit testing shape that defines the entity’s interactive entity is defined by the CollisionComponent. To configure an entity for input but avoid any sort of physics-related processing, add an InputTargetComponent and CollisionComponent, but disable the CollisionComponent for collision detection, for example:

// Enable the entity for input.
myEntity.components.set(InputTargetComponent())

// Create a collision component with an empty group and mask.
var collision = CollisionComponent(shapes: [.generateSphere(radius: 0.1)])
collision.filter = CollisionFilter(group: [], mask: [])
myEntity.components.set(collision)

InputTargetComponent behaves hierarchically, so if it is added to an entity that has descendants with CollisionComponents, those shapes will be used for input handling. The isEnabled flag can be used to override this behavior by adding the InputTargetComponent to a descendant and setting isEnabled to false.

InputTargetComponent’s allowedInputTypes property allows the entity to only receive the provided types of input. This property also propagates down the hierarchy, but if a descendant also has an InputTargetComponent defined, its allowedInputTypes property overrides the value provided by the ancestor.

Topics

Structures

Initializers

Instance Properties

See Also

Direct and indirect gestures