Trait InputAction

Source
pub trait InputAction:
    Debug
    + Send
    + Sync
    + 'static {
    type Output: ActionOutput;

    const CONSUME_INPUT: bool = true;
    const ACCUMULATION: Accumulation = Accumulation::Cumulative;
    const REQUIRE_RESET: bool = false;
}
Expand description

Marker for a gameplay-related action.

Needs to be bound to actions using Actions::bind.

To implement the trait you can use the InputAction derive to reduce boilerplate:

#[derive(Debug, InputAction)]
#[input_action(output = Vec2)]
struct Move;

Optionally you can pass consume_input and/or accumulation:

#[derive(Debug, InputAction)]
#[input_action(output = Vec2, accumulation = Cumulative, consume_input = false)]
struct Move;

All parameters match corresponding data in the trait.

Provided Associated Constants§

Source

const CONSUME_INPUT: bool = true

Specifies whether this action should swallow any Inputs bound to it or allow them to pass through to affect other actions.

Inputs are consumed when the action state is not equal to ActionState::None. For details, see Actions.

Consuming is global and affect actions in all contexts.

Source

const ACCUMULATION: Accumulation = Accumulation::Cumulative

Associated accumulation behavior.

Source

const REQUIRE_RESET: bool = false

Require inputs to be zero before the first activation and continue to consume them even after context removal until inputs become zero again.

This way new instances won’t react to currently held inputs until they are released. This prevents unintended behavior where switching or layering contexts using the same key could cause an immediate switch back, as buttons are rarely pressed for only a single frame.

Required Associated Types§

Source

type Output: ActionOutput

What type of value this action will output.

  • Use bool for button-like actions (e.g., Jump).
  • Use f32 for single-axis actions (e.g., Zoom).
  • For multi-axis actions, like Move, use Vec2 or Vec3.

This type will also be used for value field on events e.g. Fired::value, Canceled::value.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§